diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java index 7862feea..2e681fb8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductController.java @@ -1,35 +1,17 @@ -/* -* 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 cn.ysk.cashier.controller.product; import cn.ysk.cashier.annotation.Log; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.vo.TbProductVo; import cn.ysk.cashier.service.product.TbProductService; import cn.ysk.cashier.dto.product.TbProductQueryCriteria; -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 java.util.List; -import javax.servlet.http.HttpServletResponse; /** * @website https://eladmin.vip @@ -67,6 +49,12 @@ public class TbProductController { return tbProductService.findByProductList(productList); } + @PostMapping("/upProSort") + @ApiOperation("修改商品排序") + public ResponseEntity upProSort(@RequestBody TbProductSortCriteria param){ + tbProductService.upProSort(param); + return new ResponseEntity<>(HttpStatus.OK); + } @PostMapping @Log("新增商品:#resources.name") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java index cf590f76..8c2d5749 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java @@ -1,21 +1,7 @@ -/* -* 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 cn.ysk.cashier.controller.product; import cn.ysk.cashier.annotation.Log; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.service.product.TbProductService; import cn.ysk.cashier.dto.product.TbProductQueryCriteria; import cn.ysk.cashier.pojo.product.TbProductGroup; @@ -69,6 +55,13 @@ public class TbProductGroupController { return new ResponseEntity<>(tbProductGroupService.findByIdProduct(productGroup),HttpStatus.OK); } + @PostMapping("/upGroupSort") + @ApiOperation("修改分组排序") + public ResponseEntity upProSort(@RequestBody TbProductSortCriteria param){ + tbProductGroupService.upSort(param); + return new ResponseEntity<>(HttpStatus.OK); + } + @PostMapping @Log("新增商品分组:#resources.name") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbShopCategoryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbShopCategoryController.java index 17b41a01..a4f88219 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbShopCategoryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbShopCategoryController.java @@ -1,34 +1,15 @@ -/* -* 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 cn.ysk.cashier.controller.product; import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.pojo.product.TbShopCategory; import cn.ysk.cashier.service.product.TbShopCategoryService; import cn.ysk.cashier.dto.product.TbShopCategoryQueryCriteria; -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 diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopStorageController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopStorageController.java index 1ebba2b4..68a22826 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopStorageController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopStorageController.java @@ -5,9 +5,9 @@ import cn.ysk.cashier.dto.shop.TbShopStorageNumDto; import cn.ysk.cashier.dto.shop.TbShopStorageQueryCriteria; import cn.ysk.cashier.dto.shop.TbShopStorageRecordQueryCriteria; import cn.ysk.cashier.pojo.shop.TbShopStorage; -import cn.ysk.cashier.pojo.shop.TbShopStorageRecord; import cn.ysk.cashier.service.shop.TbShopStorageRecordService; import cn.ysk.cashier.service.shop.TbShopStorageService; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; @@ -17,13 +17,12 @@ import org.springframework.http.ResponseEntity; 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; @RestController @RequiredArgsConstructor @Api(tags = "存酒管理") @RequestMapping("/api/storage") +@Slf4j public class TbShopStorageController { private final TbShopStorageService tbShopStorageService; @@ -62,4 +61,11 @@ public class TbShopStorageController { public ResponseEntity queryTbShopStorageRecord(TbShopStorageRecordQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(tbShopStorageRecordService.queryAll(criteria,pageable),HttpStatus.OK); } + + @PostMapping("countRecord") + @ApiOperation("存酒统计") + public ResponseEntity queryTbOrderPayCount(@RequestBody TbShopStorageQueryCriteria criteria){ + Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize()); + return new ResponseEntity<>(tbShopStorageService.countStorage(criteria,pageable),HttpStatus.OK); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductSortCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductSortCriteria.java new file mode 100644 index 00000000..9f3b8aa3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductSortCriteria.java @@ -0,0 +1,16 @@ +package cn.ysk.cashier.dto.product; + +import lombok.Data; + +import java.util.List; + + +@Data +public class TbProductSortCriteria { + + private Integer strId; + + private Integer endId; + + private List ids; +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbCountStorageDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbCountStorageDto.java new file mode 100644 index 00000000..40179094 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbCountStorageDto.java @@ -0,0 +1,21 @@ +package cn.ysk.cashier.dto.shop; + +import lombok.Data; + +@Data +public class TbCountStorageDto { + private String name; + private String imgUrl; + private Long savNum; + private Long expNum; + + public TbCountStorageDto() { + } + + public TbCountStorageDto(String name,String imgUrl, Long savNum, Long expNum) { + this.name = name; + this.imgUrl = imgUrl; + this.savNum = savNum; + this.expNum = expNum; + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageGoodQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageGoodQueryCriteria.java index f07964c2..7eb40110 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageGoodQueryCriteria.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageGoodQueryCriteria.java @@ -28,4 +28,10 @@ public class TbShopStorageGoodQueryCriteria { private Integer page = 0; private Integer size = 10; + + public void setShopId(Integer shopId) { + if (shopId != null && shopId != 1) { + this.shopId = shopId; + } + } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageQueryCriteria.java index d9eea3fe..64ffc765 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageQueryCriteria.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopStorageQueryCriteria.java @@ -3,24 +3,40 @@ package cn.ysk.cashier.dto.shop; import cn.ysk.cashier.annotation.Query; import lombok.Data; +import java.util.StringJoiner; + @Data public class TbShopStorageQueryCriteria { - /** 模糊 */ + /** + * 模糊 + */ @Query(type = Query.Type.INNER_LIKE) private String name; - /** 精确 */ + /** + * 精确 + */ @Query private Integer status; - /** 精确 */ + /** + * 精确 + */ @Query private String telphone; - /** 精确 */ + /** + * 精确 + */ @Query private Integer shopId; - private Integer page=0; - private Integer size=10; + private Integer page = 0; + private Integer size = 10; + + public void setShopId(Integer shopId) { + if (shopId != null && shopId != 1) { + this.shopId = shopId; + } + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/quartz/task/TestTask.java b/eladmin-system/src/main/java/cn/ysk/cashier/quartz/task/TestTask.java index ece2f11a..a2b57340 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/quartz/task/TestTask.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/quartz/task/TestTask.java @@ -15,7 +15,9 @@ */ package cn.ysk.cashier.quartz.task; +import cn.ysk.cashier.repository.shop.TbShopStorageRepository; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -27,12 +29,15 @@ import org.springframework.stereotype.Service; @Service public class TestTask { + @Autowired + private TbShopStorageRepository storageRepository; + public void run(){ log.info("run 执行成功"); } public void run1(String str){ - log.info("run1 执行成功,参数为: {}" + str); + log.info("run1 执行成功,参数为: {}" , str); } public void run2(){ @@ -40,7 +45,9 @@ public class TestTask { } - public void orderSum(){ - + public void expStorage(){ + log.info("存酒过期开始执行"); + storageRepository.expStorage(); + log.info("存酒过期执行结束"); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java index 26c25770..1dd4ebb9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java @@ -151,7 +151,7 @@ public interface TbOrderInfoRepository extends JpaRepository :startTime AND info.createdAt < :endTime " + - "AND info.orderType = 'cash' " + + "AND info.payType = 'cash' " + "AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) ") TbOrderPayCountVo queryOrderPayCash(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductGroupRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductGroupRepository.java index ff3d36db..063d4e3e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductGroupRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductGroupRepository.java @@ -1,26 +1,12 @@ -/* -* 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 cn.ysk.cashier.repository.product; - import cn.ysk.cashier.pojo.product.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; +import java.util.List; + /** * @website https://eladmin.vip * @author lyf @@ -31,6 +17,10 @@ public interface TbProductGroupRepository extends JpaRepository findByIds(List productIds); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index 74886ee4..5c17b700 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -1,18 +1,3 @@ -/* -* 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 cn.ysk.cashier.repository.product; import cn.ysk.cashier.pojo.product.TbProduct; @@ -32,7 +17,7 @@ import java.util.List; public interface TbProductRepository extends JpaRepository, JpaSpecificationExecutor { - @Query("SELECT product from TbProduct product where product.id in :productIds") + @Query("SELECT product from TbProduct product where product.id in :productIds order by product.sort") List findByIds(List productIds); @Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbShopStorageRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbShopStorageRepository.java index a2b34f93..aef907af 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbShopStorageRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/shop/TbShopStorageRepository.java @@ -1,8 +1,13 @@ package cn.ysk.cashier.repository.shop; +import cn.ysk.cashier.dto.shop.TbCountStorageDto; +import cn.ysk.cashier.dto.shop.TbShopStorageQueryCriteria; import cn.ysk.cashier.pojo.shop.TbShopStorage; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; /** * @website https://eladmin.vip @@ -10,4 +15,20 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @date 2024-05-21 **/ public interface TbShopStorageRepository extends JpaRepository, JpaSpecificationExecutor { + + + @Query("SELECT new cn.ysk.cashier.dto.shop.TbCountStorageDto(" + + "storage.name, " + + "storage.imgUrl, " + + "SUM( CASE WHEN storage.status = 1 THEN storage.num ELSE 0 END), " + + "SUM( CASE WHEN storage.status = 2 THEN storage.num ELSE 0 END)" + + ") " + + "FROM TbShopStorage storage " + + "WHERE (:shopId IS NULL OR storage.shopId = :shopId) " + + "GROUP BY storage.name " + + "ORDER BY SUM(CASE WHEN storage.status = 1 THEN storage.num ELSE 0 END) desc") + Page countStorage(Integer shopId, Pageable pageable); + + @Query(value = "UPDATE tb_shop_storage SET `status` = '2' WHERE exp_time > DATE_ADD( NOW(), INTERVAL -2 DAY ) AND exp_time < NOW() AND `status` = '1'",nativeQuery = true) + void expStorage(); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/order/TbOrderInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/order/TbOrderInfoServiceImpl.java index 7b3b2044..a15d191a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/order/TbOrderInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/order/TbOrderInfoServiceImpl.java @@ -175,6 +175,9 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService { case "wx_lite": dto.setPayType("微信小程序支付"); break; + case "deposit": + dto.setPayType("储值卡支付"); + break; default: dto.setPayType(tbOrderInfo.getSendType()); break; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java index d3baa204..f80a1fba 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java @@ -1,20 +1,6 @@ -/* -* 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 cn.ysk.cashier.service.impl.productimpl; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.pojo.product.TbProduct; import cn.ysk.cashier.repository.product.TbProductRepository; import cn.ysk.cashier.pojo.product.TbProductGroup; @@ -28,6 +14,8 @@ import cn.ysk.cashier.config.security.service.dto.OnlineUserDto; import lombok.RequiredArgsConstructor; import cn.ysk.cashier.service.product.TbProductGroupService; import cn.ysk.cashier.mapper.product.TbProductGroupMapper; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -64,8 +52,9 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { @Override public Map queryAll(TbProductGroupQueryCriteria criteria, Pageable pageable){ + PageRequest sort = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("sort")); Page page = tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) -> - QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + QueryHelp.getPredicate(root,criteria,criteriaBuilder),sort); return PageUtil.toPage(page.map(tbProductGroupMapper::toDto)); } @@ -98,6 +87,8 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { public TbProductGroupDto create(TbProductGroup resources) { resources.setCreatedAt(Instant.now().toEpochMilli()); resources.setUpdatedAt(Instant.now().toEpochMilli()); + TbProductGroup save = tbProductGroupRepository.save(resources); + save.setSort(save.getId()); return tbProductGroupMapper.toDto(tbProductGroupRepository.save(resources)); } @@ -115,6 +106,54 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { tbProductGroupRepository.save(tbProductGroup); } + @Transactional(rollbackFor = Exception.class) + @Override + public void upSort(TbProductSortCriteria param) { + Integer strSort = tbProductGroupRepository.findById(param.getStrId()).get().getSort(); + Integer endSort = tbProductGroupRepository.findById(param.getEndId()).get().getSort(); + List list = tbProductGroupRepository.findByIds(param.getIds()); + Integer sort = 0; + Integer strIndex = -1; + if(strSort= 0; i--) { + TbProductGroup product = list.get(i); + if(product.getId().equals(param.getEndId())) { + sort=product.getSort(); + strIndex=i; + } + if(!strIndex.equals(-1)){ + if (product.getId().equals(param.getStrId())){ + product.setSort(sort); + tbProductGroupRepository.save(product); + break; + } + TbProductGroup product1 = list.get(i - 1); + product.setSort(product1.getSort()); + tbProductGroupRepository.save(product); + } + } + }else { + for (int i = 0; i < list.size(); i++) { + TbProductGroup product = list.get(i); + if(product.getId().equals(param.getEndId())) { + sort=product.getSort(); + strIndex=i; + } + if(!strIndex.equals(-1)){ + if (product.getId().equals(param.getStrId())){ + product.setSort(sort); + tbProductGroupRepository.save(product); + break; + } + Integer nextIndex= i + 1; + TbProductGroup product1 = list.get(nextIndex); + product.setSort(product1.getSort()); + tbProductGroupRepository.save(product); + } + } + } + } + @Override public void deleteAll(Integer[] ids) { for (Integer id : ids) { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java index ca35d7d3..8889d511 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java @@ -1,18 +1,3 @@ -/* - * 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 cn.ysk.cashier.service.impl.productimpl; import cn.hutool.core.bean.BeanUtil; @@ -20,6 +5,7 @@ import cn.hutool.core.bean.copier.CopyOptions; import cn.ysk.cashier.dto.TbPlatformDictDto; import cn.ysk.cashier.dto.product.TbProductDto; import cn.ysk.cashier.dto.product.TbProductQueryCriteria; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.dto.shop.TbCouponCategoryDto; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mapper.product.TbProductMapper; @@ -35,7 +21,6 @@ import cn.ysk.cashier.repository.shop.TbShopUserDutyDetailRepository; import cn.ysk.cashier.service.TbPlatformDictService; import cn.ysk.cashier.service.product.TbProductService; import cn.ysk.cashier.service.shop.TbCouponCategoryService; -import cn.ysk.cashier.service.shop.TbPurchaseNoticeService; import cn.ysk.cashier.utils.*; import cn.ysk.cashier.vo.TbProductVo; import com.alibaba.fastjson.JSONArray; @@ -88,7 +73,7 @@ public class TbProductServiceImpl implements TbProductService { @Override public Map queryAll(TbProductQueryCriteria criteria) { - Sort sort = Sort.by(Sort.Direction.DESC, "id"); + Sort sort = Sort.by(Sort.Direction.ASC, "sort"); Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), sort); //查询商品数据 Page page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); @@ -331,6 +316,10 @@ public class TbProductServiceImpl implements TbProductService { if (resources.getUnitId() != null) { product.setUnitId(resources.getUnitId()); } + if ("sku".equals(resources.getTypeEnum())) { + List collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList()); + product.setLowPrice(collect.get(0)); + } if ("group".equals(resources.getTypeEnum())) { //套餐内容 if (!resources.getGroupSnap().isEmpty()) { @@ -348,10 +337,11 @@ public class TbProductServiceImpl implements TbProductService { } } TbProduct save = tbProductRepository.save(product); - if (save.getId() == null) { throw new BadRequestException("添加商品失败"); } + save.setSort(save.getId()); + tbProductRepository.save(product); //sku if (resources.getSkuList() != null) { List skuList = new ArrayList<>(); @@ -401,8 +391,11 @@ public class TbProductServiceImpl implements TbProductService { product.setIsFreeFreight(1); product.setStatus(1); product.setUpdatedAt(Instant.now().toEpochMilli()); - product.setCategoryId(resources.getCategoryId().toString()); product.setImages(resources.getImages().toString()); + if ("sku".equals(resources.getTypeEnum())) { + List collect = resources.getSkuList().stream().map(TbProductSku::getSalePrice).sorted().collect(Collectors.toList()); + product.setLowPrice(collect.get(0)); + } if ("group".equals(resources.getTypeEnum())) { //套餐内容 if (!resources.getGroupSnap().isEmpty()) { @@ -420,6 +413,8 @@ public class TbProductServiceImpl implements TbProductService { } noticeRepository.save(resources.getNotices()); + }else { + product.setCategoryId(resources.getCategoryId().toString()); } TbProduct save = tbProductRepository.save(product); @@ -452,6 +447,15 @@ public class TbProductServiceImpl implements TbProductService { productSkuResult.setTagSnap(resources.getSkuSnap()); productSkuResult.setId(save.getId()); tbProductSkuResultRepository.save(productSkuResult); + }else if ("group".equals(resources.getTypeEnum())) { + TbPurchaseNotice notices = resources.getNotices(); + if (StringUtils.isBlank(notices.getDateUsed()) + && StringUtils.isBlank(notices.getAvailableTime()) + && StringUtils.isBlank(notices.getBookingType()) + && StringUtils.isBlank(notices.getRefundPolicy())) { + throw new BadRequestException("修改购买须知失败,必填项未填写"); + } + noticeRepository.save(resources.getNotices()); } } @@ -462,6 +466,54 @@ public class TbProductServiceImpl implements TbProductService { tbProductRepository.updateIsHot(id); } + @Transactional(rollbackFor = Exception.class) + @Override + public void upProSort(TbProductSortCriteria param) { + Integer strSort = tbProductRepository.findById(param.getStrId()).get().getSort(); + Integer endSort = tbProductRepository.findById(param.getEndId()).get().getSort(); + List list = tbProductRepository.findByIds(param.getIds()); + Integer sort = 0; + Integer strIndex = -1; + if(strSort= 0; i--) { + TbProduct product = list.get(i); + if(product.getId().equals(param.getEndId())) { + sort=product.getSort(); + strIndex=i; + } + if(!strIndex.equals(-1)){ + if (product.getId().equals(param.getStrId())){ + product.setSort(sort); + tbProductRepository.save(product); + break; + } + TbProduct product1 = list.get(i - 1); + product.setSort(product1.getSort()); + tbProductRepository.save(product); + } + } + }else { + for (int i = 0; i < list.size(); i++) { + TbProduct product = list.get(i); + if(product.getId().equals(param.getEndId())) { + sort=product.getSort(); + strIndex=i; + } + if(!strIndex.equals(-1)){ + if (product.getId().equals(param.getStrId())){ + product.setSort(sort); + tbProductRepository.save(product); + break; + } + Integer nextIndex= i + 1; + TbProduct product1 = list.get(nextIndex); + product.setSort(product1.getSort()); + tbProductRepository.save(product); + } + } + } + } + @Override @Transactional public void deleteAll(Integer[] ids) { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java index 86d67d5e..a19dc962 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java @@ -15,7 +15,9 @@ */ package cn.ysk.cashier.service.impl.productimpl; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.exception.BadRequestException; +import cn.ysk.cashier.pojo.product.TbProductGroup; import cn.ysk.cashier.pojo.product.TbShopCategory; import cn.ysk.cashier.utils.ValidationUtil; import cn.ysk.cashier.utils.FileUtil; @@ -117,6 +119,8 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService { if (StringUtils.isNotBlank(resources.getPid())){ resources.setTree(Integer.valueOf(resources.getPid().trim())); } + TbShopCategory save = tbShopCategoryRepository.save(resources); + save.setSort(save.getId()); return tbShopCategoryRepository.save(resources); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopStorageServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopStorageServiceImpl.java index 3f763c30..825907cb 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopStorageServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopStorageServiceImpl.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.service.impl.shopimpl; +import cn.ysk.cashier.dto.shop.TbCountStorageDto; import cn.ysk.cashier.dto.shop.TbShopStorageDto; import cn.ysk.cashier.dto.shop.TbShopStorageNumDto; import cn.ysk.cashier.dto.shop.TbShopStorageQueryCriteria; @@ -53,6 +54,12 @@ public class TbShopStorageServiceImpl implements TbShopStorageService { return tbShopStorageMapper.toDto(tbShopStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); } + @Override + public Map countStorage(TbShopStorageQueryCriteria criteria,Pageable pageable){ + Page page = tbShopStorageRepository.countStorage(criteria.getShopId(), pageable); + return PageUtil.toPage(page); + } + @Override @Transactional public TbShopStorageDto findById(Integer id) { @@ -67,7 +74,13 @@ public class TbShopStorageServiceImpl implements TbShopStorageService { resources.setStatus(1); resources.setSavTime(new Timestamp(System.currentTimeMillis())); resources.setExpTime(new Timestamp(System.currentTimeMillis() + 86400000 * resources.getExpDay())); - return tbShopStorageMapper.toDto(tbShopStorageRepository.save(resources)); + TbShopStorage save = tbShopStorageRepository.save(resources); + TbShopStorageRecord record = new TbShopStorageRecord(); + record.setStorageId(resources.getId()); + record.setTime(new Timestamp(System.currentTimeMillis())); + record.setContent("存入"+ resources.getNum() + resources.getUnit() + resources.getName()); + storageRecordService.create(record); + return tbShopStorageMapper.toDto(save); } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductGroupService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductGroupService.java index d04dc3cb..4d32326c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductGroupService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductGroupService.java @@ -1,20 +1,6 @@ -/* -* 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 cn.ysk.cashier.service.product; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.pojo.product.TbProduct; import cn.ysk.cashier.pojo.product.TbProductGroup; import cn.ysk.cashier.dto.product.TbProductGroupDto; @@ -73,6 +59,7 @@ public interface TbProductGroupService { */ void update(TbProductGroup resources); + void upSort(TbProductSortCriteria param); /** * 多选删除 * @param ids / diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java index 2026bc9b..8c72e8c5 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbProductService.java @@ -1,25 +1,10 @@ -/* -* 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 cn.ysk.cashier.service.product; +import cn.ysk.cashier.dto.product.TbProductSortCriteria; import cn.ysk.cashier.pojo.product.TbProduct; import cn.ysk.cashier.vo.TbProductVo; import cn.ysk.cashier.dto.product.TbProductDto; import cn.ysk.cashier.dto.product.TbProductQueryCriteria; -import org.springframework.data.domain.Pageable; import java.util.Map; import java.util.List; import java.io.IOException; @@ -72,6 +57,8 @@ public interface TbProductService { */ void update(TbProductVo resources); + void upProSort(TbProductSortCriteria param); + /** * 多选删除 * @param ids / diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbShopCategoryService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbShopCategoryService.java index 6420c521..460431e7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbShopCategoryService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/product/TbShopCategoryService.java @@ -18,7 +18,6 @@ package cn.ysk.cashier.service.product; import cn.ysk.cashier.pojo.product.TbShopCategory; import cn.ysk.cashier.dto.product.TbShopCategoryDto; import cn.ysk.cashier.dto.product.TbShopCategoryQueryCriteria; -import org.springframework.data.domain.Pageable; import java.util.Map; import java.util.List; import java.io.IOException; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopStorageService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopStorageService.java index a3cb1fe9..715d9624 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopStorageService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopStorageService.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.service.shop; +import cn.ysk.cashier.dto.shop.TbCountStorageDto; import cn.ysk.cashier.dto.shop.TbShopStorageDto; import cn.ysk.cashier.dto.shop.TbShopStorageNumDto; import cn.ysk.cashier.dto.shop.TbShopStorageQueryCriteria; @@ -31,6 +32,8 @@ public interface TbShopStorageService { */ List queryAll(TbShopStorageQueryCriteria criteria); + Map countStorage(TbShopStorageQueryCriteria criteria,Pageable pageable); + /** * 根据ID查询 * @param id ID