From eec0a28082dbf2259ace0daf9f7544e0f12b522d Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Sun, 21 Jan 2024 10:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=93=B6=E7=AB=AF=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=8C=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/zhengjie/utils/ListUtil.java | 24 +++ .../src/main/java/me/zhengjie/AppRun.java | 1 + .../productInfo/product/domain/TbProduct.java | 7 +- .../product/domain/TbProductVo.java | 2 + .../repository/TbProductRepository.java | 7 + .../product/rest/TbProductController.java | 13 +- .../product/service/TbProductService.java | 7 +- .../service/dto/TbProductQueryCriteria.java | 6 + .../service/impl/TbProductServiceImpl.java | 114 +++++++++++-- .../repository/TbProductGroupRepository.java | 5 + .../rest/TbProductGroupController.java | 9 ++ .../service/TbProductGroupService.java | 3 + .../impl/TbProductGroupServiceImpl.java | 37 ++++- .../repository/TbProductSkuRepository.java | 14 ++ .../domain/TbProductStockDetail.java | 151 ++++++++++++++++++ .../TbProductStockDetailRepository.java | 28 ++++ .../rest/TbProductStockDetailController.java | 87 ++++++++++ .../service/TbProductStockDetailService.java | 83 ++++++++++ .../service/dto/TbProductStockDetailDto.java | 104 ++++++++++++ .../TbProductStockDetailQueryCriteria.java | 44 +++++ .../impl/TbProductStockDetailServiceImpl.java | 128 +++++++++++++++ .../mapstruct/TbProductStockDetailMapper.java | 32 ++++ .../shopInfo/table/domain/TbShopTable.java | 106 ++++++++++++ .../repository/TbShopTableRepository.java | 28 ++++ .../table/rest/TbShopTableController.java | 87 ++++++++++ .../table/service/TbShopTableService.java | 83 ++++++++++ .../table/service/dto/TbShopTableDto.java | 71 ++++++++ .../service/dto/TbShopTableQueryCriteria.java | 40 +++++ .../service/impl/TbShopTableServiceImpl.java | 117 ++++++++++++++ .../service/mapstruct/TbShopTableMapper.java | 32 ++++ 30 files changed, 1444 insertions(+), 26 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/domain/TbProductStockDetail.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/repository/TbProductStockDetailRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/rest/TbProductStockDetailController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/TbProductStockDetailService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/impl/TbProductStockDetailServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/mapstruct/TbProductStockDetailMapper.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/domain/TbShopTable.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/repository/TbShopTableRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/rest/TbShopTableController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/TbShopTableService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/impl/TbShopTableServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/mapstruct/TbShopTableMapper.java diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/ListUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/ListUtil.java index 7ebd5b95..e1d0663b 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/ListUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/ListUtil.java @@ -5,11 +5,14 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author lyf @@ -23,6 +26,27 @@ public class ListUtil { } + public static List stringChangeStringList(String listString){ + // 使用Fastjson将JSON字符串转换为JSONArray对象 + listString = listString.replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", ""); + List stringList = Stream.of(listString.split(",")) + .map(String::trim) + .collect(Collectors.toList()); + return stringList; + } + public static List stringChangeIntegerList(List listString){ + + // method1 创建一个Integer类型的集合,循环遍历String类型的数组并把数据添加进集合 + List integerList = new ArrayList<>(); + for (String s : listString) { + integerList.add(Integer.parseInt(s)); + } + System.out.println(integerList); + return integerList; +// return listString.stream() +// .map(Integer::valueOf) +// .collect(Collectors.toList()); + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/AppRun.java b/eladmin-system/src/main/java/me/zhengjie/AppRun.java index fa4d67ff..a3cd32fc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/AppRun.java +++ b/eladmin-system/src/main/java/me/zhengjie/AppRun.java @@ -65,4 +65,5 @@ public class AppRun { public String index() { return "Backend service started successfully"; } + } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java index 6a581898..0a8b1641 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java @@ -38,6 +38,7 @@ public class TbProduct implements Serializable { @Id @Column(name = "`id`") + @GeneratedValue(strategy = GenerationType.IDENTITY) @ApiModelProperty(value = "id") private Integer id; @@ -170,7 +171,7 @@ public class TbProduct implements Serializable { @Column(name = "`is_del`",nullable = false) @NotNull @ApiModelProperty(value = "是否回收站 0-否,1回收站") - private Integer isDel; + private Integer isDel = 0; @Column(name = "`is_stock`") @ApiModelProperty(value = "是否开启库存") @@ -183,7 +184,7 @@ public class TbProduct implements Serializable { @Column(name = "`is_free_freight`",nullable = false) @NotNull @ApiModelProperty(value = "是否免邮1-是 0-否") - private Integer isFreeFreight; + private Integer isFreeFreight=1; @Column(name = "`freight_id`") @ApiModelProperty(value = "邮费模版") @@ -204,7 +205,7 @@ public class TbProduct implements Serializable { @Column(name = "`is_delete`",nullable = false) @NotNull @ApiModelProperty(value = "是否删除") - private Integer isDelete; + private Integer isDelete = 0; @Column(name = "`notice`") @ApiModelProperty(value = "购买须知") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java index f33d1f61..aba2a2a8 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java @@ -207,4 +207,6 @@ public class TbProductVo { private List skuList; private HashMap specsInfo; + + } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java index 836e3795..bb17dcde 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java @@ -18,6 +18,9 @@ package me.zhengjie.modules.productInfo.product.repository; import me.zhengjie.modules.productInfo.product.domain.TbProduct; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; /** * @website https://eladmin.vip @@ -25,4 +28,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @date 2023-12-11 **/ public interface TbProductRepository extends JpaRepository, JpaSpecificationExecutor { + + + @Query("SELECT product from TbProduct product where product.id in :productIds") + List findByIds(List productIds); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java index 9bfa9b68..a53c9337 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java @@ -29,6 +29,7 @@ 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.servlet.http.HttpServletResponse; /** @@ -67,14 +68,20 @@ public class TbProductController { public Object queryTbProductInfo(@PathVariable("product") Integer product)throws Exception{ return tbProductService.findByProductId(product); } - + @GetMapping ("/productList") + @Log("查询/product") + @ApiOperation("查询/product") + @PreAuthorize("@el.check('tbProduct:list')") + public Object queryTbProductInfo(@RequestParam List productList){ + return tbProductService.findByProductList(productList); + } @PostMapping @Log("新增/product") @ApiOperation("新增/product") @PreAuthorize("@el.check('tbProduct:add')") - public ResponseEntity createTbProduct(@Validated @RequestBody TbProduct resources){ + public ResponseEntity createTbProduct(@Validated @RequestBody TbProductVo resources){ return new ResponseEntity<>(tbProductService.create(resources),HttpStatus.CREATED); } @@ -82,7 +89,7 @@ public class TbProductController { @Log("修改/product") @ApiOperation("修改/product") @PreAuthorize("@el.check('tbProduct:edit')") - public ResponseEntity updateTbProduct(@Validated @RequestBody TbProduct resources){ + public ResponseEntity updateTbProduct(@Validated @RequestBody TbProductVo resources){ tbProductService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java index 9ea81549..8e7f6d4d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java @@ -57,18 +57,21 @@ public interface TbProductService { TbProductVo findByProductId(Integer id)throws Exception; + + ListfindByProductList(List productList); + /** * 创建 * @param resources / * @return TbProductDto */ - TbProductDto create(TbProduct resources); + Object create(TbProductVo resources); /** * 编辑 * @param resources / */ - void update(TbProduct resources); + void update(TbProductVo resources); /** * 多选删除 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java index 09af5739..288b6e09 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java @@ -40,6 +40,9 @@ public class TbProductQueryCriteria{ @Query private String name; + @Query + private String categoryId; + /** 精确 */ @Query private BigDecimal packFee; @@ -115,4 +118,7 @@ public class TbProductQueryCriteria{ /** 精确 */ @Query private Integer furnishExpress; + + @Query + private String typeEnum; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java index 2945e600..956230d1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java @@ -15,6 +15,8 @@ */ package me.zhengjie.modules.productInfo.product.service.impl; +import cn.hutool.core.bean.BeanUtil; +import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.productInfo.product.domain.TbProduct; import me.zhengjie.modules.productInfo.product.domain.TbProductVo; import me.zhengjie.modules.productInfo.product.repository.TbProductRepository; @@ -36,9 +38,11 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import java.time.Instant; import java.util.*; import java.io.IOException; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; /** @@ -57,6 +61,7 @@ public class TbProductServiceImpl implements TbProductService { private final TbShopUnitRepository tbShopUnitRepository; private final TbProductSpecRepository tbProductSpecRepository; + @Override public Map queryAll(TbProductQueryCriteria criteria, Pageable pageable){ //查询商品数据 @@ -69,7 +74,9 @@ public class TbProductServiceImpl implements TbProductService { productId.add(product.getId().toString()); //记录单位id if (product.getUnitId() != null){ - unitId.add(Integer.valueOf(product.getUnitId())); + if (!"".equals(product.getUnitId())){ + unitId.add(Integer.valueOf(product.getUnitId().trim())); + } } //记录规格id specId.add(product.getSpecId()); @@ -126,7 +133,7 @@ public class TbProductServiceImpl implements TbProductService { tbProductVoList.add(tbProductVo); } System.out.println(tbProductVoList); - return PageUtil.toPage(tbProductVoList,tbProductVoList.size()); + return PageUtil.toPage(tbProductVoList,page.getTotalElements()); } @Override @@ -150,13 +157,38 @@ public class TbProductServiceImpl implements TbProductService { HashMap map = new HashMap<>(); - map.put(tbProductSpec.get().getName(),tbProductSpec.get().getSpecList()); - tbProductVo.setUnitName(tbShopUnits.get().getName()); - tbProductVo.setSkuList(tbProductSkus.get()); - tbProductVo.setSpecsInfo(map); + //商品规格 + if (tbProductSpec.get() == null){ + tbProductVo.setSpecsInfo(map); + }else { + map.put(tbProductSpec.get().getName(),tbProductSpec.get().getSpecList()); + tbProductVo.setSpecsInfo(map); + } + //单位 + if (tbShopUnits.get() == null){ + tbProductVo.setUnitName(null); + }else { + tbProductVo.setUnitName(tbShopUnits.get().getName()); + } + //sku + if (tbProductSkus.get() == null){ + tbProductVo.setSkuList(new ArrayList<>()); + }else { + tbProductVo.setSkuList(tbProductSkus.get()); + } return tbProductVo; } + @Override + public List findByProductList(List productList) { + List productListInt = productList.stream() + .map(Integer::parseInt) + .collect(Collectors.toList()); + List byIds = tbProductRepository.findByIds(productListInt); + + return byIds; + } + @Override public List queryAll(TbProductQueryCriteria criteria){ return tbProductMapper.toDto(tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); @@ -173,17 +205,73 @@ public class TbProductServiceImpl implements TbProductService { @Override @Transactional(rollbackFor = Exception.class) - public TbProductDto create(TbProduct resources) { - return tbProductMapper.toDto(tbProductRepository.save(resources)); + public Object create(TbProductVo resources) { + TbProduct product = new TbProduct(); + //组装 + BeanUtils.copyProperties(resources, product); + product.setIsDel(0); + product.setIsDelete(0); + product.setIsFreeFreight(1); + product.setStatus(1); + product.setCreatedAt(Instant.now().toEpochMilli()); + product.setUpdatedAt(Instant.now().toEpochMilli()); + TbProduct save = tbProductRepository.save(product); + + if (save.getId() == null){ + throw new BadRequestException("添加商品失败"); + } + //sku + if (resources.getSkuList() != null) { + List skuList = new ArrayList<>(); + for (TbProductSku sku : resources.getSkuList()) { + sku.setProductId(String.valueOf(save.getId())); + sku.setShopId(save.getShopId()); + sku.setCreatedAt(Instant.now().toEpochMilli()); + sku.setUpdatedAt(Instant.now().toEpochMilli()); + skuList.add(sku); + } + tbProductSkuRepository.saveAll(skuList); + } + return resources; } + + public static void main(String[] args) { + System.out.println(UUID.randomUUID().toString().substring(0, 16)); + } + + @Override @Transactional(rollbackFor = Exception.class) - public void update(TbProduct resources) { - TbProduct tbProduct = tbProductRepository.findById(resources.getId()).orElseGet(TbProduct::new); - ValidationUtil.isNull( tbProduct.getId(),"TbProduct","id",resources.getId()); - tbProduct.copy(resources); - tbProductRepository.save(tbProduct); + public void update(TbProductVo resources) { + TbProduct product = new TbProduct(); + //组装 + BeanUtils.copyProperties(resources, product); + product.setIsDel(0); + product.setIsDelete(0); + product.setIsFreeFreight(1); + product.setStatus(1); + product.setUpdatedAt(Instant.now().toEpochMilli()); + TbProduct save = tbProductRepository.save(product); + + //sku + if (resources.getSkuList() != null) { + if ("sku".equals(save.getTypeEnum())){ + tbProductSkuRepository.deleteByProductId(String.valueOf(save.getId())); + } + List skuList = new ArrayList<>(); + for (TbProductSku sku : resources.getSkuList()) { + sku.setProductId(String.valueOf(save.getId())); + sku.setShopId(save.getShopId()); + product.setUpdatedAt(Instant.now().toEpochMilli()); + skuList.add(sku); + } + tbProductSkuRepository.saveAll(skuList); + + } +// ValidationUtil.isNull( tbProduct.getId(),"TbProduct","id",resources.getId()); +// tbProduct.copy(resources); +// tbProductRepository.save(tbProduct); } @Override diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java index e8214dd6..a4ae37e9 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java @@ -18,6 +18,8 @@ package me.zhengjie.modules.productInfo.productGroup.repository; import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; /** * @website https://eladmin.vip @@ -28,4 +30,7 @@ public interface TbProductGroupRepository extends JpaRepository(tbProductGroupService.queryAll(criteria,pageable),HttpStatus.OK); } + @GetMapping("/{productGroup}") + @Log("查询product/group") + @ApiOperation("查询product/group") + @PreAuthorize("@el.check('tbProductGroup:list')") + public ResponseEntity queryTbProductGroup(@PathVariable("productGroup") Integer productGroup){ + return new ResponseEntity<>(tbProductGroupService.findByIdProduct(productGroup),HttpStatus.OK); + } + + @PostMapping @Log("新增product/group") @ApiOperation("新增product/group") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java index e86aa3ff..82a726e1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java @@ -15,6 +15,7 @@ */ package me.zhengjie.modules.productInfo.productGroup.service; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupDto; import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupQueryCriteria; @@ -50,6 +51,8 @@ public interface TbProductGroupService { */ List queryAll(TbProductGroupQueryCriteria criteria); + + List findByIdProduct(Integer productGroup); /** * 根据ID查询 * @param id ID diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java index 33f8029a..0ec09462 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java @@ -15,6 +15,10 @@ */ package me.zhengjie.modules.productInfo.productGroup.service.impl; +import com.alibaba.fastjson.JSONArray; +import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.repository.TbProductRepository; import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; import me.zhengjie.modules.productInfo.productGroup.service.vo.AddProduct; import me.zhengjie.modules.productInfo.productGroup.repository.TbProductGroupRepository; @@ -22,8 +26,7 @@ import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupDt import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupQueryCriteria; import me.zhengjie.modules.security.service.OnlineUserService; import me.zhengjie.modules.security.service.dto.OnlineUserDto; -import me.zhengjie.utils.ValidationUtil; -import me.zhengjie.utils.FileUtil; +import me.zhengjie.utils.*; import lombok.RequiredArgsConstructor; import me.zhengjie.modules.productInfo.productGroup.service.TbProductGroupService; import me.zhengjie.modules.productInfo.productGroup.service.mapstruct.TbProductGroupMapper; @@ -33,8 +36,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import me.zhengjie.utils.PageUtil; -import me.zhengjie.utils.QueryHelp; + +import java.time.Instant; import java.util.List; import java.util.Map; import java.io.IOException; @@ -55,6 +58,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { private final TbProductGroupRepository tbProductGroupRepository; private final TbProductGroupMapper tbProductGroupMapper; + private final TbProductRepository tbProductRepository; @Resource private OnlineUserService onlineUserService; @@ -64,7 +68,6 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { Page page = tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(tbProductGroupMapper::toDto)); } @@ -73,6 +76,23 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { return tbProductGroupMapper.toDto(tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); } + @Override + public List findByIdProduct(Integer productGroup) { + TbProductGroup tbProductGroup = tbProductGroupRepository.findById(productGroup).orElseGet(TbProductGroup::new); + if (tbProductGroup.getProductIds() != null){ + List list = ListUtil.stringChangeStringList(tbProductGroup.getProductIds()); + + List intList = new ArrayList<>(); + for (String str : list) { + intList.add(Integer.parseInt(str)); + } + System.out.println(intList); + + return tbProductRepository.findByIds(ListUtil.stringChangeIntegerList(list)); + } + return new ArrayList<>(); + } + @Override @Transactional public TbProductGroupDto findById(Integer id) { @@ -84,6 +104,8 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { @Override @Transactional(rollbackFor = Exception.class) public TbProductGroupDto create(TbProductGroup resources) { + resources.setCreatedAt(Instant.now().toEpochMilli()); + resources.setUpdatedAt(Instant.now().toEpochMilli()); return tbProductGroupMapper.toDto(tbProductGroupRepository.save(resources)); } @@ -91,6 +113,11 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { @Transactional(rollbackFor = Exception.class) public void update(TbProductGroup resources) { TbProductGroup tbProductGroup = tbProductGroupRepository.findById(resources.getId()).orElseGet(TbProductGroup::new); +// TbProductGroup byName = tbProductGroupRepository.findByName(resources.getName(), resources.getShopId()); +// if (byName != null){ +// throw new BadRequestException("名称重复"); +// } + tbProductGroup.setUpdatedAt(Instant.now().toEpochMilli()); ValidationUtil.isNull( tbProductGroup.getId(),"TbProductGroup","id",resources.getId()); tbProductGroup.copy(resources); tbProductGroupRepository.save(tbProductGroup); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java index 420f3081..2f11596e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java @@ -16,11 +16,14 @@ package me.zhengjie.modules.productInfo.productSku.repository; import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import org.apache.ibatis.annotations.Insert; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import javax.transaction.Transactional; import java.util.List; /** @@ -36,4 +39,15 @@ public interface TbProductSkuRepository extends JpaRepository searchSku(@Param("productId")String productId); + @Transactional + @Modifying + @Query("DELETE FROM TbProductSku sku WHERE sku.productId = :productId") + Integer deleteByProductId(@Param("productId") String productId); + +// @Insert("INSERT INTO TbProductSku sku(sku.shopId,sku.barCode,sku.productId,sku.originPrice,sku.costPrice,sku.memberPrice,sku.salePrice,sku.stockNumber,sku.firstShared) " + +// "VALUES (#{item.shopId},#{item.barCode},#{item.productId},#{item.originPrice},#{item.costPrice},#{item.memberPrice},#{item.salePrice},#{item.stockNumber},#{sku.firstShared}) ") +// void findById(@Param("item") List skuList); + + + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/domain/TbProductStockDetail.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/domain/TbProductStockDetail.java new file mode 100644 index 00000000..1dc7277a --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/domain/TbProductStockDetail.java @@ -0,0 +1,151 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-19 +**/ +@Entity +@Data +@Table(name="tb_product_stock_detail") +public class TbProductStockDetail implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Long id; + + @Column(name = "`sku_id`") + @ApiModelProperty(value = "skuId") + private String skuId; + + @Column(name = "`product_id`") + @ApiModelProperty(value = "商品Id") + private String productId; + + @Column(name = "`product_name`") + @ApiModelProperty(value = "商品名称") + private String productName; + + @Column(name = "`is_stock`") + @ApiModelProperty(value = "是否开启库存") + private Integer isStock; + + @Column(name = "`spec_snap`") + @ApiModelProperty(value = "规格") + private String specSnap; + + @Column(name = "`unit_name`") + @ApiModelProperty(value = "商品单位") + private String unitName; + + @Column(name = "`shop_id`") + @ApiModelProperty(value = "店铺Id") + private String shopId; + + @Column(name = "`record_id`") + @ApiModelProperty(value = "recordId") + private String recordId; + + @Column(name = "`batch_number`") + @ApiModelProperty(value = "操作批次号") + private String batchNumber; + + @Column(name = "`source_path`") + @ApiModelProperty(value = "库存操作来源:收银端调用 CASHIER 系统后台调用SHOP") + private String sourcePath; + + @Column(name = "`order_id`") + @ApiModelProperty(value = "关联订单Id") + private String orderId; + + @Column(name = "`sub_type`",nullable = false) + @NotNull + @ApiModelProperty(value = " 1入库2出库") + private Integer subType; + + @Column(name = "`type`",nullable = false) + @NotBlank + @ApiModelProperty(value = "purchase采购入库 transfer调拔入库 ") + private String type; + + @Column(name = "`left_number`") + @ApiModelProperty(value = "上次剩余数量") + private Integer leftNumber; + + @Column(name = "`stock_time`") + @ApiModelProperty(value = "出入库时间") + private Long stockTime; + + @Column(name = "`stock_number`") + @ApiModelProperty(value = "本次操作库存数量") + private Double stockNumber; + + @Column(name = "`cost_amount`") + @ApiModelProperty(value = "入库合计成本金额") + private BigDecimal costAmount; + + @Column(name = "`sales_amount`") + @ApiModelProperty(value = "出售合计金额") + private BigDecimal salesAmount; + + @Column(name = "`operator`") + @ApiModelProperty(value = "操作人") + private String operator; + + @Column(name = "`remark`") + @ApiModelProperty(value = "备注") + private String remark; + + @Column(name = "`stock_snap`") + @ApiModelProperty(value = "库存镜像") + private String stockSnap; + + @Column(name = "`bar_code`") + @ApiModelProperty(value = "barCode") + private String barCode; + + @Column(name = "`cover_img`") + @ApiModelProperty(value = "coverImg") + private String coverImg; + + @Column(name = "`created_at`",nullable = false) + @NotNull + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`",nullable = false) + @NotNull + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + public void copy(TbProductStockDetail source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/repository/TbProductStockDetailRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/repository/TbProductStockDetailRepository.java new file mode 100644 index 00000000..721a89d3 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/repository/TbProductStockDetailRepository.java @@ -0,0 +1,28 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.repository; + +import me.zhengjie.modules.productInfo.productStock.domain.TbProductStockDetail; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-19 +**/ +public interface TbProductStockDetailRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/rest/TbProductStockDetailController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/rest/TbProductStockDetailController.java new file mode 100644 index 00000000..935a9b24 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/rest/TbProductStockDetailController.java @@ -0,0 +1,87 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.productInfo.productStock.domain.TbProductStockDetail; +import me.zhengjie.modules.productInfo.productStock.service.TbProductStockDetailService; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-19 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "/product/Stock管理") +@RequestMapping("/api/tbProductStockDetail") +public class TbProductStockDetailController { + + private final TbProductStockDetailService tbProductStockDetailService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbProductStockDetail:list')") + public void exportTbProductStockDetail(HttpServletResponse response, TbProductStockDetailQueryCriteria criteria) throws IOException { + tbProductStockDetailService.download(tbProductStockDetailService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询/product/Stock") + @ApiOperation("查询/product/Stock") + @PreAuthorize("@el.check('tbProductStockDetail:list')") + public ResponseEntity queryTbProductStockDetail(TbProductStockDetailQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbProductStockDetailService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增/product/Stock") + @ApiOperation("新增/product/Stock") + @PreAuthorize("@el.check('tbProductStockDetail:add')") + public ResponseEntity createTbProductStockDetail(@Validated @RequestBody TbProductStockDetail resources){ + return new ResponseEntity<>(tbProductStockDetailService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改/product/Stock") + @ApiOperation("修改/product/Stock") + @PreAuthorize("@el.check('tbProductStockDetail:edit')") + public ResponseEntity updateTbProductStockDetail(@Validated @RequestBody TbProductStockDetail resources){ + tbProductStockDetailService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除/product/Stock") + @ApiOperation("删除/product/Stock") + @PreAuthorize("@el.check('tbProductStockDetail:del')") + public ResponseEntity deleteTbProductStockDetail(@RequestBody Long[] ids) { + tbProductStockDetailService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/TbProductStockDetailService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/TbProductStockDetailService.java new file mode 100644 index 00000000..0d8729c0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/TbProductStockDetailService.java @@ -0,0 +1,83 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.service; + +import me.zhengjie.modules.productInfo.productStock.domain.TbProductStockDetail; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailDto; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author lyf +* @date 2024-01-19 +**/ +public interface TbProductStockDetailService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbProductStockDetailQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbProductStockDetailQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbProductStockDetailDto + */ + TbProductStockDetailDto findById(Long id); + + /** + * 创建 + * @param resources / + * @return TbProductStockDetailDto + */ + TbProductStockDetailDto create(TbProductStockDetail resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbProductStockDetail resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailDto.java new file mode 100644 index 00000000..c18dba4d --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailDto.java @@ -0,0 +1,104 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.service.dto; + +import lombok.Data; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-19 +**/ +@Data +public class TbProductStockDetailDto implements Serializable { + + private Long id; + + /** skuId */ + private String skuId; + + /** 商品Id */ + private String productId; + + /** 商品名称 */ + private String productName; + + /** 是否开启库存 */ + private Integer isStock; + + /** 规格 */ + private String specSnap; + + /** 商品单位 */ + private String unitName; + + /** 店铺Id */ + private String shopId; + + private String recordId; + + /** 操作批次号 */ + private String batchNumber; + + /** 库存操作来源:收银端调用 CASHIER 系统后台调用SHOP */ + private String sourcePath; + + /** 关联订单Id */ + private String orderId; + + /** 1入库2出库 */ + private Integer subType; + + /** purchase采购入库 transfer调拔入库 +stockpile存酒入库 +2盘点入库3退货入库4期初5生产归还入库6内部令用归还7借出归还8其它入库9调拔出库sale销售出库11盘点出库12锁定13生产领料14内部领用15借用出库16其它出库17报废出库 */ + private String type; + + /** 上次剩余数量 */ + private Integer leftNumber; + + /** 出入库时间 */ + private Long stockTime; + + /** 本次操作库存数量 */ + private Double stockNumber; + + /** 入库合计成本金额 */ + private BigDecimal costAmount; + + /** 出售合计金额 */ + private BigDecimal salesAmount; + + /** 操作人 */ + private String operator; + + /** 备注 */ + private String remark; + + /** 库存镜像 */ + private String stockSnap; + + private String barCode; + + private String coverImg; + + private Long createdAt; + + private Long updatedAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailQueryCriteria.java new file mode 100644 index 00000000..e9f3aab9 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/dto/TbProductStockDetailQueryCriteria.java @@ -0,0 +1,44 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-19 +**/ +@Data +public class TbProductStockDetailQueryCriteria{ + + /** 精确 */ + @Query + private String skuId; + + /** 精确 */ + @Query + private String productId; + + /** 精确 */ + @Query + private String productName; + /** BETWEEN */ + @Query(type = Query.Type.BETWEEN) + private List createdAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/impl/TbProductStockDetailServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/impl/TbProductStockDetailServiceImpl.java new file mode 100644 index 00000000..d55d9bff --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/impl/TbProductStockDetailServiceImpl.java @@ -0,0 +1,128 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.service.impl; + +import me.zhengjie.modules.productInfo.productStock.domain.TbProductStockDetail; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.productInfo.productStock.repository.TbProductStockDetailRepository; +import me.zhengjie.modules.productInfo.productStock.service.TbProductStockDetailService; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailDto; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailQueryCriteria; +import me.zhengjie.modules.productInfo.productStock.service.mapstruct.TbProductStockDetailMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import me.zhengjie.utils.PageUtil; +import me.zhengjie.utils.QueryHelp; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-19 +**/ +@Service +@RequiredArgsConstructor +public class TbProductStockDetailServiceImpl implements TbProductStockDetailService { + + private final TbProductStockDetailRepository tbProductStockDetailRepository; + private final TbProductStockDetailMapper tbProductStockDetailMapper; + + @Override + public Map queryAll(TbProductStockDetailQueryCriteria criteria, Pageable pageable){ + Page page = tbProductStockDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbProductStockDetailMapper::toDto)); + } + + @Override + public List queryAll(TbProductStockDetailQueryCriteria criteria){ + return tbProductStockDetailMapper.toDto(tbProductStockDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbProductStockDetailDto findById(Long id) { + TbProductStockDetail tbProductStockDetail = tbProductStockDetailRepository.findById(id).orElseGet(TbProductStockDetail::new); + ValidationUtil.isNull(tbProductStockDetail.getId(),"TbProductStockDetail","id",id); + return tbProductStockDetailMapper.toDto(tbProductStockDetail); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbProductStockDetailDto create(TbProductStockDetail resources) { + return tbProductStockDetailMapper.toDto(tbProductStockDetailRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbProductStockDetail resources) { + TbProductStockDetail tbProductStockDetail = tbProductStockDetailRepository.findById(resources.getId()).orElseGet(TbProductStockDetail::new); + ValidationUtil.isNull( tbProductStockDetail.getId(),"TbProductStockDetail","id",resources.getId()); + tbProductStockDetail.copy(resources); + tbProductStockDetailRepository.save(tbProductStockDetail); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + tbProductStockDetailRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbProductStockDetailDto tbProductStockDetail : all) { + Map map = new LinkedHashMap<>(); + map.put("skuId", tbProductStockDetail.getSkuId()); + map.put("商品Id", tbProductStockDetail.getProductId()); + map.put("商品名称", tbProductStockDetail.getProductName()); + map.put("是否开启库存", tbProductStockDetail.getIsStock()); + map.put("规格", tbProductStockDetail.getSpecSnap()); + map.put("商品单位", tbProductStockDetail.getUnitName()); + map.put("店铺Id", tbProductStockDetail.getShopId()); + map.put(" recordId", tbProductStockDetail.getRecordId()); + map.put("操作批次号", tbProductStockDetail.getBatchNumber()); + map.put("库存操作来源:收银端调用 CASHIER 系统后台调用SHOP", tbProductStockDetail.getSourcePath()); + map.put("关联订单Id", tbProductStockDetail.getOrderId()); + map.put(" 1入库2出库", tbProductStockDetail.getSubType()); + map.put("purchase采购入库 transfer调拔入库 ", tbProductStockDetail.getType()); + map.put("上次剩余数量", tbProductStockDetail.getLeftNumber()); + map.put("出入库时间", tbProductStockDetail.getStockTime()); + map.put("本次操作库存数量", tbProductStockDetail.getStockNumber()); + map.put("入库合计成本金额", tbProductStockDetail.getCostAmount()); + map.put("出售合计金额", tbProductStockDetail.getSalesAmount()); + map.put("操作人", tbProductStockDetail.getOperator()); + map.put("备注", tbProductStockDetail.getRemark()); + map.put("库存镜像", tbProductStockDetail.getStockSnap()); + map.put(" barCode", tbProductStockDetail.getBarCode()); + map.put(" coverImg", tbProductStockDetail.getCoverImg()); + map.put(" createdAt", tbProductStockDetail.getCreatedAt()); + map.put(" updatedAt", tbProductStockDetail.getUpdatedAt()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/mapstruct/TbProductStockDetailMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/mapstruct/TbProductStockDetailMapper.java new file mode 100644 index 00000000..d205ad09 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productStock/service/mapstruct/TbProductStockDetailMapper.java @@ -0,0 +1,32 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.productInfo.productStock.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.productInfo.productStock.domain.TbProductStockDetail; +import me.zhengjie.modules.productInfo.productStock.service.dto.TbProductStockDetailDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-19 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbProductStockDetailMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/domain/TbShopTable.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/domain/TbShopTable.java new file mode 100644 index 00000000..91ea90ef --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/domain/TbShopTable.java @@ -0,0 +1,106 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-18 +**/ +@Entity +@Data +@Table(name="tb_shop_table") +public class TbShopTable implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "自增id") + private Integer id; + + @Column(name = "`name`",nullable = false) + @NotBlank + @ApiModelProperty(value = "name") + private String name; + + @Column(name = "`shop_id`",nullable = false) + @NotNull + @ApiModelProperty(value = "shopId") + private Integer shopId; + + @Column(name = "`max_capacity`") + @ApiModelProperty(value = "客座数,允许的客座数量") + private Integer maxCapacity; + + @Column(name = "`sort`") + @ApiModelProperty(value = "台桌排序") + private Integer sort; + + @Column(name = "`area_id`") + @ApiModelProperty(value = "区域Id") + private String areaId; + + @Column(name = "`is_predate`") + @ApiModelProperty(value = "是否接受网络预定") + private Integer isPredate; + + @Column(name = "`predate_amount`") + @ApiModelProperty(value = "网络预定台桌支付金额") + private BigDecimal predateAmount; + + @Column(name = "`status`",nullable = false) + @NotBlank + @ApiModelProperty(value = "subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中") + private String status; + + @Column(name = "`type`") + @ApiModelProperty(value = "台桌计算价格类型,0-低消类型,amount 2计时类型") + private Integer type; + + @Column(name = "`amount`") + @ApiModelProperty(value = "当type=0时,amount生效,为台桌的低消金额") + private BigDecimal amount; + + @Column(name = "`perhour`") + @ApiModelProperty(value = "当type=2时perhour生效,为计时类型,每小时收款金额") + private BigDecimal perhour; + + @Column(name = "`view`") + @ApiModelProperty(value = "台桌展示图---预留") + private String view; + + @Column(name = "`created_at`") + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`") + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + public void copy(TbShopTable source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/repository/TbShopTableRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/repository/TbShopTableRepository.java new file mode 100644 index 00000000..890b63c0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/repository/TbShopTableRepository.java @@ -0,0 +1,28 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.repository; + +import me.zhengjie.modules.shopInfo.table.domain.TbShopTable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-18 +**/ +public interface TbShopTableRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/rest/TbShopTableController.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/rest/TbShopTableController.java new file mode 100644 index 00000000..2bef09c5 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/rest/TbShopTableController.java @@ -0,0 +1,87 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.shopInfo.table.domain.TbShopTable; +import me.zhengjie.modules.shopInfo.table.service.TbShopTableService; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-18 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "/shop/table管理") +@RequestMapping("/api/tbShopTable") +public class TbShopTableController { + + private final TbShopTableService tbShopTableService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbShopTable:list')") + public void exportTbShopTable(HttpServletResponse response, TbShopTableQueryCriteria criteria) throws IOException { + tbShopTableService.download(tbShopTableService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询/shop/table") + @ApiOperation("查询/shop/table") + @PreAuthorize("@el.check('tbShopTable:list')") + public ResponseEntity queryTbShopTable(TbShopTableQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbShopTableService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增/shop/table") + @ApiOperation("新增/shop/table") + @PreAuthorize("@el.check('tbShopTable:add')") + public ResponseEntity createTbShopTable(@Validated @RequestBody TbShopTable resources){ + return new ResponseEntity<>(tbShopTableService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改/shop/table") + @ApiOperation("修改/shop/table") + @PreAuthorize("@el.check('tbShopTable:edit')") + public ResponseEntity updateTbShopTable(@Validated @RequestBody TbShopTable resources){ + tbShopTableService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除/shop/table") + @ApiOperation("删除/shop/table") + @PreAuthorize("@el.check('tbShopTable:del')") + public ResponseEntity deleteTbShopTable(@RequestBody Integer[] ids) { + tbShopTableService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/TbShopTableService.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/TbShopTableService.java new file mode 100644 index 00000000..4bb2e8d8 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/TbShopTableService.java @@ -0,0 +1,83 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.service; + +import me.zhengjie.modules.shopInfo.table.domain.TbShopTable; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableDto; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author lyf +* @date 2024-01-18 +**/ +public interface TbShopTableService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbShopTableQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbShopTableQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbShopTableDto + */ + TbShopTableDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbShopTableDto + */ + TbShopTableDto create(TbShopTable resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbShopTable resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableDto.java new file mode 100644 index 00000000..94e33d38 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableDto.java @@ -0,0 +1,71 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.service.dto; + +import lombok.Data; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-18 +**/ +@Data +public class TbShopTableDto implements Serializable { + + /** 自增id */ + private Integer id; + + private String name; + + private Integer shopId; + + /** 客座数,允许的客座数量 */ + private Integer maxCapacity; + + /** 台桌排序 */ + private Integer sort; + + /** 区域Id */ + private String areaId; + + /** 是否接受网络预定 */ + private Integer isPredate; + + /** 网络预定台桌支付金额 */ + private BigDecimal predateAmount; + + /** subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中 */ + private String status; + + /** 台桌计算价格类型,0-低消类型,amount 2计时类型 */ + private Integer type; + + /** 当type=0时,amount生效,为台桌的低消金额 */ + private BigDecimal amount; + + /** 当type=2时perhour生效,为计时类型,每小时收款金额 */ + private BigDecimal perhour; + + /** 台桌展示图---预留 */ + private String view; + + private Long createdAt; + + private Long updatedAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableQueryCriteria.java new file mode 100644 index 00000000..4e679717 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/dto/TbShopTableQueryCriteria.java @@ -0,0 +1,40 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-18 +**/ +@Data +public class TbShopTableQueryCriteria{ + + /** 精确 */ + @Query + private String name; + + /** 精确 */ + @Query + private Integer shopId; + + @Query + private String areaId; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/impl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/impl/TbShopTableServiceImpl.java new file mode 100644 index 00000000..91e50b10 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/impl/TbShopTableServiceImpl.java @@ -0,0 +1,117 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.service.impl; + +import me.zhengjie.modules.shopInfo.table.domain.TbShopTable; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.shopInfo.table.repository.TbShopTableRepository; +import me.zhengjie.modules.shopInfo.table.service.TbShopTableService; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableDto; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableQueryCriteria; +import me.zhengjie.modules.shopInfo.table.service.mapstruct.TbShopTableMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import me.zhengjie.utils.PageUtil; +import me.zhengjie.utils.QueryHelp; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-18 +**/ +@Service +@RequiredArgsConstructor +public class TbShopTableServiceImpl implements TbShopTableService { + + private final TbShopTableRepository tbShopTableRepository; + private final TbShopTableMapper tbShopTableMapper; + + @Override + public Map queryAll(TbShopTableQueryCriteria criteria, Pageable pageable){ + Page page = tbShopTableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbShopTableMapper::toDto)); + } + + @Override + public List queryAll(TbShopTableQueryCriteria criteria){ + return tbShopTableMapper.toDto(tbShopTableRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbShopTableDto findById(Integer id) { + TbShopTable tbShopTable = tbShopTableRepository.findById(id).orElseGet(TbShopTable::new); + ValidationUtil.isNull(tbShopTable.getId(),"TbShopTable","id",id); + return tbShopTableMapper.toDto(tbShopTable); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbShopTableDto create(TbShopTable resources) { + return tbShopTableMapper.toDto(tbShopTableRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbShopTable resources) { + TbShopTable tbShopTable = tbShopTableRepository.findById(resources.getId()).orElseGet(TbShopTable::new); + ValidationUtil.isNull( tbShopTable.getId(),"TbShopTable","id",resources.getId()); + tbShopTable.copy(resources); + tbShopTableRepository.save(tbShopTable); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbShopTableRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbShopTableDto tbShopTable : all) { + Map map = new LinkedHashMap<>(); + map.put(" name", tbShopTable.getName()); + map.put(" shopId", tbShopTable.getShopId()); + map.put("客座数,允许的客座数量", tbShopTable.getMaxCapacity()); + map.put("台桌排序", tbShopTable.getSort()); + map.put("区域Id", tbShopTable.getAreaId()); + map.put("是否接受网络预定", tbShopTable.getIsPredate()); + map.put("网络预定台桌支付金额", tbShopTable.getPredateAmount()); + map.put("subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中", tbShopTable.getStatus()); + map.put("台桌计算价格类型,0-低消类型,amount 2计时类型", tbShopTable.getType()); + map.put("当type=0时,amount生效,为台桌的低消金额", tbShopTable.getAmount()); + map.put("当type=2时perhour生效,为计时类型,每小时收款金额", tbShopTable.getPerhour()); + map.put("台桌展示图---预留", tbShopTable.getView()); + map.put(" createdAt", tbShopTable.getCreatedAt()); + map.put(" updatedAt", tbShopTable.getUpdatedAt()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/mapstruct/TbShopTableMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/mapstruct/TbShopTableMapper.java new file mode 100644 index 00000000..941b64b7 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/table/service/mapstruct/TbShopTableMapper.java @@ -0,0 +1,32 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.modules.shopInfo.table.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.shopInfo.table.domain.TbShopTable; +import me.zhengjie.modules.shopInfo.table.service.dto.TbShopTableDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-18 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbShopTableMapper extends BaseMapper { + +} \ No newline at end of file