From 8dfe061cc14384bfc49ca5f05c511d514d9d4ffb Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Thu, 25 Jan 2024 09:07:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=EF=BC=8C=E4=BE=9B=E5=BA=94=E5=95=86=E8=BF=9B=E8=B4=A7/?= =?UTF-8?q?=E9=80=80=E8=B4=A7=E8=B4=A6=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbProductStockDetailRepository.java | 5 +- .../rest/TbProductStockDetailController.java | 10 + .../service/TbProductStockDetailService.java | 4 + .../impl/TbProductStockDetailServiceImpl.java | 17 +- .../repository/TbShopPurveyorRepository.java | 10 + .../dto/TbShopPurveyorQueryCriteria.java | 4 +- .../impl/TbShopPurveyorServiceImpl.java | 6 + .../domain/TbShopPurveyorTransact.java | 109 +++++++++ .../TbShopPurveyorTransactRepository.java | 43 ++++ .../TbShopPurveyorTransactController.java | 88 ++++++++ .../TbShopPurveyorTransactService.java | 85 +++++++ .../service/VO/PurveyorTransactVO.java | 39 ++++ .../dto/TbShopPurveyorTransactDto.java | 65 ++++++ .../TbShopPurveyorTransactQueryCriteria.java | 49 ++++ .../TbShopPurveyorTransactServiceImpl.java | 211 ++++++++++++++++++ .../TbShopPurveyorTransactMapper.java | 32 +++ 16 files changed, 770 insertions(+), 7 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/domain/TbShopPurveyorTransact.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/repository/TbShopPurveyorTransactRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/rest/TbShopPurveyorTransactController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/TbShopPurveyorTransactService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/VO/PurveyorTransactVO.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/impl/TbShopPurveyorTransactServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/mapstruct/TbShopPurveyorTransactMapper.java 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 index baacc2e9..585effc6 100644 --- 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 @@ -20,8 +20,10 @@ import org.springframework.data.domain.Page; 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 org.w3c.dom.stylesheets.LinkStyle; +import java.math.BigDecimal; import java.util.List; /** @@ -31,5 +33,6 @@ import java.util.List; **/ public interface TbProductStockDetailRepository extends JpaRepository, JpaSpecificationExecutor { - + @Query("select sum(detail.stockNumber) from TbProductStockDetail detail where detail.productId =:product") + BigDecimal sumStockNumber(@Param("product") String product); } \ 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 index a4170018..f3e20761 100644 --- 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 @@ -66,8 +66,18 @@ public class TbProductStockDetailController { public ResponseEntity queryPage(@RequestBody TbProductStockDetailQueryCriteria criteria){ return new ResponseEntity<>(tbProductStockDetailService.queryPage(criteria),HttpStatus.OK); } + @GetMapping("/sum") + @Log("查询/product/Stock") + public ResponseEntity sumType(TbProductStockDetailQueryCriteria criteria){ + return new ResponseEntity<>(tbProductStockDetailService.sumStockNumber(criteria.getProductId()),HttpStatus.OK); + } + /** + * 出库/入库 + * @param resources + * @return + */ @PostMapping @Log("新增/product/Stock") @ApiOperation("新增/product/Stock") 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 index f27c8213..8e2d597b 100644 --- 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 @@ -19,6 +19,9 @@ 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.math.BigDecimal; +import java.util.HashMap; import java.util.Map; import java.util.List; import java.io.IOException; @@ -56,6 +59,7 @@ public interface TbProductStockDetailService { */ TbProductStockDetailDto findById(Long id); + HashMap sumStockNumber(String productId); /** * 创建 * @param resources / 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 index 12dc7f81..2dade512 100644 --- 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 @@ -33,13 +33,12 @@ 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.math.BigDecimal; +import java.util.*; import java.io.IOException; import javax.persistence.criteria.*; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.LinkedHashMap; /** * @website https://eladmin.vip @@ -86,9 +85,19 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ return tbProductStockDetailMapper.toDto(tbProductStockDetail); } + @Override + public HashMap sumStockNumber(String productId) { + BigDecimal bigDecimal = tbProductStockDetailRepository.sumStockNumber(productId); + HashMap map = new HashMap<>(); + map.put("exchange",bigDecimal); + return map; + } + @Override @Transactional(rollbackFor = Exception.class) public TbProductStockDetailDto create(TbProductStockDetail resources) { + + return tbProductStockDetailMapper.toDto(tbProductStockDetailRepository.save(resources)); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/repository/TbShopPurveyorRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/repository/TbShopPurveyorRepository.java index 826bc45a..8291ad52 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/repository/TbShopPurveyorRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/repository/TbShopPurveyorRepository.java @@ -16,8 +16,12 @@ package me.zhengjie.modules.shopInfo.shopPurveyor.repository; import me.zhengjie.modules.shopInfo.shopPurveyor.domain.TbShopPurveyor; +import org.apache.ibatis.annotations.Param; 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 +29,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @date 2024-01-22 **/ public interface TbShopPurveyorRepository extends JpaRepository, JpaSpecificationExecutor { + + @Query(value = "select purveyor.* from tb_shop_purveyor purveyor where id in :ids LIMIT :page, :size ",nativeQuery = true) + List findByIds(@Param("ids") List ids, @Param("page")Integer page, @Param("size")Integer size); + + @Query("select count(1) from TbShopPurveyor purveyor where purveyor.shopId = :shopId") + Integer findByCount(@Param("shop") String shopId); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/dto/TbShopPurveyorQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/dto/TbShopPurveyorQueryCriteria.java index ec19948c..7e50175a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/dto/TbShopPurveyorQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/dto/TbShopPurveyorQueryCriteria.java @@ -32,8 +32,8 @@ public class TbShopPurveyorQueryCriteria{ private String shopId; /** 精确 */ - @Query - private String name; + @Query(type = Query.Type.LEFT_LIKE) + private String purveyorName; /** 精确 */ @Query diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/impl/TbShopPurveyorServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/impl/TbShopPurveyorServiceImpl.java index 7f3e845d..bd62a9e1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/impl/TbShopPurveyorServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyor/service/impl/TbShopPurveyorServiceImpl.java @@ -30,6 +30,8 @@ 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; @@ -72,6 +74,8 @@ public class TbShopPurveyorServiceImpl implements TbShopPurveyorService { @Override @Transactional(rollbackFor = Exception.class) public TbShopPurveyorDto create(TbShopPurveyor resources) { + resources.setCreatedAt(Instant.now().toEpochMilli()); + resources.setUpdatedAt(Instant.now().toEpochMilli()); return tbShopPurveyorMapper.toDto(tbShopPurveyorRepository.save(resources)); } @@ -79,6 +83,8 @@ public class TbShopPurveyorServiceImpl implements TbShopPurveyorService { @Transactional(rollbackFor = Exception.class) public void update(TbShopPurveyor resources) { TbShopPurveyor tbShopPurveyor = tbShopPurveyorRepository.findById(resources.getId()).orElseGet(TbShopPurveyor::new); + tbShopPurveyor.setUpdatedAt(Instant.now().toEpochMilli()); + tbShopPurveyor.setSort(0); ValidationUtil.isNull( tbShopPurveyor.getId(),"TbShopPurveyor","id",resources.getId()); tbShopPurveyor.copy(resources); tbShopPurveyorRepository.save(tbShopPurveyor); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/domain/TbShopPurveyorTransact.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/domain/TbShopPurveyorTransact.java new file mode 100644 index 00000000..b58c21cc --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/domain/TbShopPurveyorTransact.java @@ -0,0 +1,109 @@ +/* +* 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.shopPurveyorTransact.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-23 +**/ +@Entity +@Data +@Table(name="tb_shop_purveyor_transact") +public class TbShopPurveyorTransact implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "自增id") + private Integer id; + + @Column(name = "`shop_id`",nullable = false) + @NotBlank + @ApiModelProperty(value = "店铺Id") + private String shopId; + + @Column(name = "`purveyor_name`") + @ApiModelProperty(value = "供应商名字") + private String purveyorName; + + @Column(name = "`purveyor_id`") + @ApiModelProperty(value = "供应商Id") + private String purveyorId; + + @Column(name = "`status`") + @ApiModelProperty(value = "0待付款1已付款 -1是否作废") + private Integer status; + + @Column(name = "`remark`") + @ApiModelProperty(value = "备注") + private String remark; + + @Column(name = "`created_at`") + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`") + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + @Column(name = "`total_amount`") + @ApiModelProperty(value = "应付金额") + private BigDecimal totalAmount; + + @Column(name = "`wait_amount`") + @ApiModelProperty(value = "待付款金额") + private BigDecimal waitAmount; + + @Column(name = "`paid_amount`") + @ApiModelProperty(value = "已支付金额") + private BigDecimal paidAmount; + + @Column(name = "`paid_at`") + @ApiModelProperty(value = "paidAt") + private Long paidAt; + + @Column(name = "`type`") + @ApiModelProperty(value = "type") + private String type; + + /** + * 上笔进货日期 + */ + private Long lastTransactAt; + + /** + *待付款笔数 + */ + private Integer waitCount; + + + + + public void copy(TbShopPurveyorTransact source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/repository/TbShopPurveyorTransactRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/repository/TbShopPurveyorTransactRepository.java new file mode 100644 index 00000000..b107adc2 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/repository/TbShopPurveyorTransactRepository.java @@ -0,0 +1,43 @@ +/* +* 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.shopPurveyorTransact.repository; + +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.domain.TbShopPurveyorTransact; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.VO.PurveyorTransactVO; +import org.apache.ibatis.annotations.Param; +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; + +import java.util.List; +import java.util.Map; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-23 +**/ +public interface TbShopPurveyorTransactRepository extends JpaRepository, JpaSpecificationExecutor { + + @Query("SELECT sum(transact.waitAmount) as waitAmount,count(transact.id) as waitCount, transact.purveyorId as purveyorId from TbShopPurveyorTransact transact " + + "where transact.purveyorId in :purveyorIds and transact.type =:type GROUP BY transact.purveyorId") + List> findByPurveyorIds(@Param("purveyorIds") List purveyorIds, @Param("type") String type); + @Query(value = "select transact.* from tb_shop_purveyor_transact transact where transact.shop_id =:shopId and transact.status =:status " + + "GROUP BY transact.purveyor_id LIMIT :page, :size ", nativeQuery = true) + List findByGroup(@Param("status")Integer status, @Param("shopId") String shopId,@Param("page") Integer page, @Param("size") Integer size); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/rest/TbShopPurveyorTransactController.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/rest/TbShopPurveyorTransactController.java new file mode 100644 index 00000000..500ef8ab --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/rest/TbShopPurveyorTransactController.java @@ -0,0 +1,88 @@ +/* +* 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.shopPurveyorTransact.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.domain.TbShopPurveyorTransact; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.TbShopPurveyorTransactService; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactQueryCriteria; +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-23 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "/shop/purveyorTransact管理") +@RequestMapping("/api/tbShopPurveyorTransact") +public class TbShopPurveyorTransactController { + + private final TbShopPurveyorTransactService tbShopPurveyorTransactService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbShopPurveyorTransact:list')") + public void exportTbShopPurveyorTransact(HttpServletResponse response, TbShopPurveyorTransactQueryCriteria criteria) throws IOException { + tbShopPurveyorTransactService.download(tbShopPurveyorTransactService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询/shop/purveyorTransact") + @ApiOperation("查询/shop/purveyorTransact") + @PreAuthorize("@el.check('tbShopPurveyorTransact:list')") + public ResponseEntity queryTbShopPurveyorTransact(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbShopPurveyorTransactService.queryTransactDate(criteria,pageable),HttpStatus.OK); +// return new ResponseEntity<>(tbShopPurveyorTransactService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增/shop/purveyorTransact") + @ApiOperation("新增/shop/purveyorTransact") + @PreAuthorize("@el.check('tbShopPurveyorTransact:add')") + public ResponseEntity createTbShopPurveyorTransact(@Validated @RequestBody TbShopPurveyorTransact resources){ + return new ResponseEntity<>(tbShopPurveyorTransactService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改/shop/purveyorTransact") + @ApiOperation("修改/shop/purveyorTransact") + @PreAuthorize("@el.check('tbShopPurveyorTransact:edit')") + public ResponseEntity updateTbShopPurveyorTransact(@Validated @RequestBody TbShopPurveyorTransact resources){ + tbShopPurveyorTransactService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除/shop/purveyorTransact") + @ApiOperation("删除/shop/purveyorTransact") + @PreAuthorize("@el.check('tbShopPurveyorTransact:del')") + public ResponseEntity deleteTbShopPurveyorTransact(@RequestBody Integer[] ids) { + tbShopPurveyorTransactService.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/shopPurveyorTransact/service/TbShopPurveyorTransactService.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/TbShopPurveyorTransactService.java new file mode 100644 index 00000000..a8f13a70 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/TbShopPurveyorTransactService.java @@ -0,0 +1,85 @@ +/* +* 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.shopPurveyorTransact.service; + +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.domain.TbShopPurveyorTransact; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.VO.PurveyorTransactVO; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactDto; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactQueryCriteria; +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-23 +**/ +public interface TbShopPurveyorTransactService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable); + Map queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbShopPurveyorTransactQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbShopPurveyorTransactDto + */ + TbShopPurveyorTransactDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbShopPurveyorTransactDto + */ + TbShopPurveyorTransactDto create(TbShopPurveyorTransact resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbShopPurveyorTransact 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/shopPurveyorTransact/service/VO/PurveyorTransactVO.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/VO/PurveyorTransactVO.java new file mode 100644 index 00000000..2ffa24aa --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/VO/PurveyorTransactVO.java @@ -0,0 +1,39 @@ +package me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.VO; + +import io.swagger.models.auth.In; +import lombok.Data; + +import javax.persistence.Entity; +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * @author lyf + */ +@Data +public class PurveyorTransactVO { + /** + * 上笔进货日期 + */ + private BigInteger lastTransactAt; + /** + * 供货商id + */ + private Integer purveyorId; + /** + * 供货商名称 + */ + private String purveyorName; + /** + * 剩余付款金额 + */ + private BigDecimal waitAmount; + /** + *待付款笔数 + */ + private BigInteger waitCount; + /** + * 0.待支付 1.已完结 + */ + private Integer type; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactDto.java new file mode 100644 index 00000000..0ac5a59b --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactDto.java @@ -0,0 +1,65 @@ +/* +* 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.shopPurveyorTransact.service.dto; + +import lombok.Data; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-23 +**/ +@Data +public class TbShopPurveyorTransactDto implements Serializable { + + /** 自增id */ + private Integer id; + + /** 店铺Id */ + private String shopId; + + /** 供应商名字 */ + private String purveyorName; + + /** 供应商Id */ + private String purveyorId; + + /** 0待付款1已付款 -1是否作废 */ + private Integer status; + + /** 备注 */ + private String remark; + + private Long createdAt; + + private Long updatedAt; + + /** 应付金额 */ + private BigDecimal totalAmount; + + /** 待付款金额 */ + private BigDecimal waitAmount; + + /** 已支付金额 */ + private BigDecimal paidAmount; + + private Long paidAt; + + private String type; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactQueryCriteria.java new file mode 100644 index 00000000..b2780fd0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/dto/TbShopPurveyorTransactQueryCriteria.java @@ -0,0 +1,49 @@ +/* +* 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.shopPurveyorTransact.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-23 +**/ +@Data +public class TbShopPurveyorTransactQueryCriteria{ + + /** 精确 */ + @Query + private String shopId; + + /** 精确 */ + @Query(type = Query.Type.LEFT_LIKE) + private String purveyorName; + + /** 精确 */ + @Query + private String purveyorId; + /** + * purveyor进货 reject退货 + */ + @Query + private String type; + + @Query + private Integer status; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/impl/TbShopPurveyorTransactServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/impl/TbShopPurveyorTransactServiceImpl.java new file mode 100644 index 00000000..c79a8207 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/impl/TbShopPurveyorTransactServiceImpl.java @@ -0,0 +1,211 @@ +/* +* 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.shopPurveyorTransact.service.impl; + +import me.zhengjie.modules.shopInfo.shopPurveyor.domain.TbShopPurveyor; +import me.zhengjie.modules.shopInfo.shopPurveyor.repository.TbShopPurveyorRepository; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.domain.TbShopPurveyorTransact; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.VO.PurveyorTransactVO; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.repository.TbShopPurveyorTransactRepository; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.TbShopPurveyorTransactService; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactDto; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactQueryCriteria; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.mapstruct.TbShopPurveyorTransactMapper; +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.math.BigDecimal; +import java.math.BigInteger; +import java.util.*; +import java.io.IOException; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import javax.servlet.http.HttpServletResponse; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-23 +**/ +@Service +@RequiredArgsConstructor +public class TbShopPurveyorTransactServiceImpl implements TbShopPurveyorTransactService { + + private final TbShopPurveyorTransactRepository tbShopPurveyorTransactRepository; + private final TbShopPurveyorTransactMapper tbShopPurveyorTransactMapper; + private final TbShopPurveyorRepository tbShopPurveyorRepository; + + private final String LEFTQUERYSQL="SELECT\n" + + "\ta.purveyor_name AS purveyorName,\n" + + "\tb.last_transact_at AS lastTransactAt,\n" + + "\tIFNULL( b.waitAmount, 0 ) AS waitAmount,\n" + + "\tIFNULL( b.waitCount, 0 ) AS waitCount,\n" + + "\ta.id AS purveyorId \n" + + "FROM\n" + + "\ttb_shop_purveyor a\n" + + "\tLEFT JOIN (\n" + + "\tSELECT\n" + + "\t\tsum( a.wait_amount ) AS waitAmount,\n" + + "\t\tcount( a.id ) AS waitCount,\n" + + "\t\ta.purveyor_id AS id,\n" + + "\t\tb.purveyor_name,\n" + + "\t\tb.last_transact_at \n" + + "\tFROM\n" + + "\t\ttb_shop_purveyor_transact a\n" + + "\t\tLEFT JOIN tb_shop_purveyor b ON a.purveyor_id = b.id \n" + + "\tWHERE " + + "a.`status` = 0 "; + private final String RIGHTQUERYSQL = " GROUP BY\n" + + "\t\tb.id \n" + + "\t) b ON a.id = b.id\n" + + "WHERE 1=1"; + @PersistenceContext + private EntityManager em; + + @Override + public Map queryAll(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable){ + + + Page pageShopPurveyor = tbShopPurveyorRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); + + Map map = new HashMap<>(); +// map.put("content",purveyorVoList); + map.put("totalElements",pageShopPurveyor.getTotalElements()); + return map; + } + + @Override + public Map queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable){ + // 构建动态SQL语句 + StringBuilder sqlQuery = new StringBuilder(LEFTQUERYSQL); + sqlQuery.append(" and b.shop_id=").append(criteria.getShopId()).append(" AND a.type=").append("'purveyor'").append(RIGHTQUERYSQL); + //没有条件时 + if (criteria.getStatus() == null && "".equals(criteria.getPurveyorName())){ + sqlQuery.append(" AND a.shop_id = ").append(criteria.getShopId()); + } + //付款状态 + if (criteria.getStatus() != null) { + sqlQuery.append(" AND a.id IN (SELECT purveyor_id FROM tb_shop_purveyor_transact WHERE shop_id AND `status` = ").append(criteria.getStatus()) + .append(" GROUP BY purveyor_id)"); + } + //供应商名字 + if (criteria.getPurveyorName() != null && !"".equals(criteria.getPurveyorName())) { + sqlQuery.append(" AND a.purveyor_name LIKE '").append(criteria.getPurveyorName()).append("%'"); + } + + //获取页码号 + int pageNum = pageable.getPageNumber(); + //获取每页大小 + int pageSize = pageable.getPageSize(); + int beginNo; + if(pageNum <=0){ + beginNo = 0; + }else{ + beginNo = (pageNum - 1) * pageSize; + } + sqlQuery.append(" LIMIT ").append(beginNo).append(",").append(pageSize); + System.out.println(sqlQuery); + Query query = em.createNativeQuery(String.valueOf(sqlQuery)); + + List resultList = query.getResultList(); + List userVOs = new ArrayList<>(); + for (Object[] result : resultList) { + PurveyorTransactVO purveyorTransactVO = new PurveyorTransactVO(); + purveyorTransactVO.setLastTransactAt((BigInteger) result[1]); + purveyorTransactVO.setPurveyorId((Integer) result[4]); + purveyorTransactVO.setPurveyorName((String) result[0]); + purveyorTransactVO.setWaitAmount((BigDecimal) result[2]); + purveyorTransactVO.setWaitCount((BigInteger) result[3]); + purveyorTransactVO.setType(purveyorTransactVO.getWaitCount().intValue()<1?1:0); + userVOs.add(purveyorTransactVO); + } + Integer byCount = tbShopPurveyorRepository.findByCount(criteria.getShopId()); + Map map = new HashMap<>(); + map.put("content",userVOs); + map.put("totalElements",byCount); + + return map; + } + + @Override + public List queryAll(TbShopPurveyorTransactQueryCriteria criteria){ + return tbShopPurveyorTransactMapper.toDto(tbShopPurveyorTransactRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbShopPurveyorTransactDto findById(Integer id) { + TbShopPurveyorTransact tbShopPurveyorTransact = tbShopPurveyorTransactRepository.findById(id).orElseGet(TbShopPurveyorTransact::new); + ValidationUtil.isNull(tbShopPurveyorTransact.getId(),"TbShopPurveyorTransact","id",id); + return tbShopPurveyorTransactMapper.toDto(tbShopPurveyorTransact); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbShopPurveyorTransactDto create(TbShopPurveyorTransact resources) { + return tbShopPurveyorTransactMapper.toDto(tbShopPurveyorTransactRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbShopPurveyorTransact resources) { + TbShopPurveyorTransact tbShopPurveyorTransact = tbShopPurveyorTransactRepository.findById(resources.getId()).orElseGet(TbShopPurveyorTransact::new); + ValidationUtil.isNull( tbShopPurveyorTransact.getId(),"TbShopPurveyorTransact","id",resources.getId()); + tbShopPurveyorTransact.copy(resources); + tbShopPurveyorTransactRepository.save(tbShopPurveyorTransact); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbShopPurveyorTransactRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbShopPurveyorTransactDto tbShopPurveyorTransact : all) { + Map map = new LinkedHashMap<>(); + map.put("店铺Id", tbShopPurveyorTransact.getShopId()); + map.put("供应商名字", tbShopPurveyorTransact.getPurveyorName()); + map.put("供应商Id", tbShopPurveyorTransact.getPurveyorId()); + map.put("0待付款1已付款 -1是否作废", tbShopPurveyorTransact.getStatus()); + map.put("备注", tbShopPurveyorTransact.getRemark()); + map.put(" createdAt", tbShopPurveyorTransact.getCreatedAt()); + map.put(" updatedAt", tbShopPurveyorTransact.getUpdatedAt()); + map.put("应付金额", tbShopPurveyorTransact.getTotalAmount()); + map.put("待付款金额", tbShopPurveyorTransact.getWaitAmount()); + map.put("已支付金额", tbShopPurveyorTransact.getPaidAmount()); + map.put(" paidAt", tbShopPurveyorTransact.getPaidAt()); + map.put(" type", tbShopPurveyorTransact.getType()); + 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/shopPurveyorTransact/service/mapstruct/TbShopPurveyorTransactMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/mapstruct/TbShopPurveyorTransactMapper.java new file mode 100644 index 00000000..9eae0c40 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopPurveyorTransact/service/mapstruct/TbShopPurveyorTransactMapper.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.shopPurveyorTransact.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.domain.TbShopPurveyorTransact; +import me.zhengjie.modules.shopInfo.shopPurveyorTransact.service.dto.TbShopPurveyorTransactDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-23 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbShopPurveyorTransactMapper extends BaseMapper { + +} \ No newline at end of file