Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-09 09:56:42 +08:00
commit b6792ccf99
8 changed files with 71 additions and 141 deletions

View File

@ -41,12 +41,6 @@ public class TbConsInfoFlowController {
public ResponseEntity<Object> stockCount(@RequestBody TbProductStockCountQueryCriteria criteria) throws ParseException {
return new ResponseEntity<>(tbConsInfoFlowService.stockCount(criteria),HttpStatus.OK);
}
//
// @PostMapping("/list")
// @ApiOperation("耗材库存统计列表")
// public ResponseEntity<Object> stockList(@RequestBody TbProductStockCountQueryCriteria criteria) throws ParseException {
// return new ResponseEntity<>(tbConsInfoFlowService.stockList(criteria),HttpStatus.OK);
// }
@PostMapping("/stock")
@ApiOperation("耗材库存记录列表")

View File

@ -18,11 +18,6 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-19
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "商品库存记录管理")
@ -60,7 +55,7 @@ public class TbProductStockDetailController {
@PostMapping("/stock")
@ApiOperation("商品库存记录列表")
public ResponseEntity<Object> queryPage(@RequestBody TbProductStockDetailQueryCriteria criteria){
public ResponseEntity<Object> queryPage(@RequestBody TbProductStockDetailQueryCriteria criteria) throws ParseException {
return new ResponseEntity<>(tbProductStockDetailService.queryPage(criteria),HttpStatus.OK);
}
// @GetMapping("/sum")

View File

@ -4,11 +4,6 @@ import cn.ysk.cashier.dto.BaseQueryDto;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-19
**/
@Data
public class TbProductStockCountQueryCriteria extends BaseQueryDto {
@ -18,6 +13,8 @@ public class TbProductStockCountQueryCriteria extends BaseQueryDto {
private String categoryId;
private String type;
private Integer page = 0;
private Integer size = 10;
@ -39,4 +36,10 @@ public class TbProductStockCountQueryCriteria extends BaseQueryDto {
this.categoryId = categoryId;
}
}
public void setType(String type) {
if (StringUtils.isNotBlank(type)) {
this.type = type;
}
}
}

View File

@ -1,42 +1,14 @@
package cn.ysk.cashier.dto.product;
import lombok.Data;
import java.util.List;
import cn.ysk.cashier.annotation.Query;
import org.apache.commons.lang3.StringUtils;
/**
* @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 shopId;
/** 精确 */
// @Query
// private String productName;
public class TbProductStockDetailQueryCriteria extends TbProductStockCountQueryCriteria{
private String column;
@Query(type = Query.Type.IN)
private List<String> type;
/** BETWEEN */
@Query(type = Query.Type.BETWEEN)
private List<Long> createdAt;
// @Query
// private Long createTime;
// @Query
// private Long endTime;
//操作类型
private List<String> types;
private Integer page;

View File

@ -9,12 +9,6 @@ import org.springframework.data.jpa.repository.Query;
import java.util.Date;
/**
* @author lyf
* @website https://eladmin.vip
* @date 2024-03-02
**/
public interface ProductStockCountRepository extends JpaRepository<TbProductStockListDto, Integer> {
@ -34,7 +28,8 @@ public interface ProductStockCountRepository extends JpaRepository<TbProductStoc
" INNER JOIN tb_product pro ON d.product_id = pro.id " +
" AND pro.shop_id = :shopId " +
" AND (:categoryId IS NULL OR pro.category_id = :categoryId) " +
" AND (:productName IS NULL OR d.product_name LIKE %:productName%) " +
" AND (:productName IS NULL OR pro.name LIKE %:productName%) " +
" AND (:type IS NULL OR pro.type_enum = :type) " +
" WHERE " +
" d.shop_id = :shopId " +
"AND d.created_at > :startTime " +
@ -47,7 +42,8 @@ public interface ProductStockCountRepository extends JpaRepository<TbProductStoc
" INNER JOIN tb_product pro ON d.product_id = pro.id " +
" and pro.shop_id = :shopId " +
" and (:categoryId IS NULL OR pro.category_id = :categoryId) " +
" AND (:productName IS NULL OR d.product_name LIKE %:productName%) " +
" AND (:productName IS NULL OR pro.name LIKE %:productName%) " +
" AND (:type IS NULL OR pro.type_enum = :type) " +
" WHERE " +
" d.shop_id = :shopId " +
" AND d.created_at > :startTime " +
@ -55,9 +51,8 @@ public interface ProductStockCountRepository extends JpaRepository<TbProductStoc
" GROUP BY " +
" d.product_id "
, nativeQuery = true)
Page<TbProductStockListDto> productStock(String shopId,
String productName,
String categoryId, long startTime, long endTime, Pageable pageable);
Page<TbProductStockListDto> productStock(String shopId, String productName, String categoryId, String type,
long startTime, long endTime, Pageable pageable);
@Query("SELECT new cn.ysk.cashier.vo.TbProductStockCountVo( " +
" SUM( pro.stockNumber ) , " +
@ -70,17 +65,18 @@ public interface ProductStockCountRepository extends JpaRepository<TbProductStoc
" SUM( CASE WHEN detail.type = '退单' THEN ABS(detail.stockNumber) ELSE 0 END ))" +
"FROM " +
" TbProductStockDetail detail " +
" INNER JOIN TbProduct pro ON detail.productId = pro.id " +
" INNER JOIN TbProduct pro ON detail.productId = pro.id " +
" AND pro.shopId = :shopId " +
" AND ( :categoryId IS NULL OR pro.categoryId = :categoryId ) " +
" AND ( :productName IS NULL OR detail.productName LIKE %:productName% ) " +
" AND ( :productName IS NULL OR pro.name LIKE %:productName% ) " +
" AND ( :type IS NULL OR pro.typeEnum = :type ) " +
"WHERE " +
" detail.shopId = :shopId " +
" AND detail.createdAt > :startTime " +
" AND detail.createdAt < :endTime")
TbProductStockCountVo productStockCount(String shopId,
String productName,
String categoryId, long startTime, long endTime);
String categoryId, String type, long startTime, long endTime);
@Query(value = "SELECT " +

View File

@ -1,35 +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 cn.ysk.cashier.repository.product;
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
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;
import org.springframework.data.repository.query.Param;
import java.math.BigDecimal;
import java.util.List;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-19
**/
public interface TbProductStockDetailRepository extends JpaRepository<TbProductStockDetail, Long>, JpaSpecificationExecutor<TbProductStockDetail> {
@Query("select sum(detail.stockNumber) from TbProductStockDetail detail where detail.productId =:product")
BigDecimal sumStockNumber(@Param("product") String product);
@Query("SELECT detail FROM TbProductStockDetail detail " +
"INNER JOIN TbProduct pro ON detail.productId = pro.id " +
"AND pro.shopId = :shopId " +
"AND (:categoryId IS NULL OR pro.categoryId = :categoryId) " +
"AND (:productName IS NULL OR pro.name LIKE %:productName%) " +
"AND (:type IS NULL OR pro.typeEnum = :type) " +
"where detail.shopId = :shopId " +
"AND detail.createdAt > :startTime " +
"AND detail.createdAt < :endTime " +
"AND detail.type IN :types " +
"ORDER BY detail.id DESC")
Page<TbProductStockDetail> findByProductParam(String shopId, String productName, String categoryId, String type,
List<String> types,
long startTime, long endTime, Pageable pageable);
}

View File

@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.dto.product.*;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbProducSkutMapper;
import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.pojo.product.TbProduct;
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
import cn.ysk.cashier.pojo.shop.TbShopUnit;
@ -29,20 +28,12 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author lyf
* @date 2024-01-19
**/
@Service
@RequiredArgsConstructor
@Slf4j
@ -55,7 +46,6 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
private final TbShopUnitRepository shopUnitRepository;
private final StockCountRepository stockCountRepository;
private final ProductStockCountRepository stockRepository;
private final EntityManager entityManager;
private final TbOrderInfoRepository tbOrderInfoRepository;
private final TbProducSkutMapper skutMapper;
@ -68,29 +58,37 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
@Override
public Map<String,Object> queryPage(TbProductStockDetailQueryCriteria criteria){
public Map<String,Object> queryPage(TbProductStockDetailQueryCriteria criteria) throws ParseException {
if (criteria.getStartTime() == null || criteria.getEndTime() == null) {
criteria.setEndTime(new Date());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
criteria.setStartTime(sdf.parse("2024-01-01"));//创建2024年1月1日的Date对象
}
if(StringUtils.isNotBlank(criteria.getColumn())){
switch (criteria.getColumn()){
case "addCountNumber":
criteria.setType(Arrays.asList("供应商入库", "盘点入库", "其他入库", "退单"));
criteria.setTypes(Arrays.asList("供应商入库", "盘点入库", "其他入库", "退单"));
break;
case "addNumber":
criteria.setType(Arrays.asList("供应商入库", "盘点入库", "其他入库"));
criteria.setTypes(Arrays.asList("供应商入库", "盘点入库", "其他入库"));
break;
case "refundNumber":
criteria.setType(Arrays.asList("退单"));
criteria.setTypes(Collections.singletonList("退单"));
break;
case "subCountNumber":
criteria.setType(Arrays.asList("供应商出库","其他出库","盘点出库","售出记录","报损"));
criteria.setTypes(Arrays.asList("供应商出库","其他出库","盘点出库","售出记录","报损"));
break;
case "subNumber":
criteria.setType(Arrays.asList("供应商出库","其他出库","盘点出库","售出记录"));
criteria.setTypes(Arrays.asList("供应商出库","其他出库","盘点出库","售出记录"));
break;
case "saleNumber":
criteria.setType(Arrays.asList("售出记录"));
criteria.setTypes(Collections.singletonList("售出记录"));
break;
case "lossNumber":
criteria.setType(Arrays.asList("报损"));
criteria.setTypes(Collections.singletonList("报损"));
break;
default:
criteria.setTypes(Arrays.asList("供应商入库", "盘点入库", "其他入库", "退单","供应商出库","其他出库","盘点出库","售出记录","报损"));
break;
}
}
@ -98,16 +96,16 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
Sort sort = Sort.by(Sort.Direction.DESC, "id");
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), sort);
Page<TbProductStockDetail> page = tbProductStockDetailRepository.findAll((root, criteriaQuery, criteriaBuilder)
-> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
Page<TbProductStockDetail> page = tbProductStockDetailRepository.findByProductParam(
criteria.getShopId().toString(), criteria.getProductName(),
criteria.getCategoryId(),criteria.getType(),
criteria.getTypes() ,
criteria.getStartTime().getTime(), criteria.getEndTime().getTime(), pageable);
Page<TbProductStockDetailDto> map = page.map(tbProductStockDetailMapper::toDto);
for (TbProductStockDetailDto tbProductStockDetailDto : map.getContent()) {
if (StrUtil.isNotBlank(tbProductStockDetailDto.getOrderId())) {
TbOrderInfo tbOrderInfo = tbOrderInfoRepository.findById(Integer.valueOf(tbProductStockDetailDto.getOrderId())).orElse(null);
if (tbOrderInfo != null) {
tbProductStockDetailDto.setOrderNo(tbOrderInfo.getOrderNo());
}
tbOrderInfoRepository.findById(Integer.valueOf(tbProductStockDetailDto.getOrderId())).ifPresent(tbOrderInfo -> tbProductStockDetailDto.setOrderNo(tbOrderInfo.getOrderNo()));
}
tbProductStockDetailDto.setTypes();
}
@ -125,7 +123,7 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
criteria.setStartTime(sdf.parse("2024-01-01"));//创建2024年1月1日的Date对象
}
return stockRepository.productStockCount(criteria.getShopId().toString(), criteria.getProductName(),
criteria.getCategoryId(), criteria.getStartTime().getTime(), criteria.getEndTime().getTime());
criteria.getCategoryId(),criteria.getType(), criteria.getStartTime().getTime(), criteria.getEndTime().getTime());
}
@Override
@ -140,12 +138,10 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
Page<TbProductStockListDto> tbProductStockCountDtos = stockRepository.productStock(
criteria.getShopId().toString(),
criteria.getProductName(),
criteria.getCategoryId(),
criteria.getCategoryId(),criteria.getType(),
criteria.getStartTime().getTime(), criteria.getEndTime().getTime(), pageable);
if (!tbProductStockCountDtos.isEmpty()) {
tbProductStockCountDtos.getContent().parallelStream().forEach(s->{
s.setCountNumber(s.getStockNumber().add(s.getSubCountNumber()));
});
tbProductStockCountDtos.getContent().parallelStream().forEach(s-> s.setCountNumber(s.getStockNumber().add(s.getSubCountNumber())));
}
return PageUtil.toPage(tbProductStockCountDtos);
}
@ -164,14 +160,6 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
return tbProductStockDetailMapper.toDto(tbProductStockDetail);
}
@Override
public HashMap<String, BigDecimal> sumStockNumber(String productId) {
BigDecimal bigDecimal = tbProductStockDetailRepository.sumStockNumber(productId);
HashMap<String, BigDecimal> map = new HashMap<>();
map.put("exchange",bigDecimal);
return map;
}
@Override
public void frmLoss(TbProductFrmLossDto resources) {
TbProduct product = tbProductRepository.findById(Integer.valueOf(resources.getProductId())).orElse(null);

View File

@ -2,27 +2,18 @@ package cn.ysk.cashier.service.product;
import cn.ysk.cashier.dto.product.TbProductFrmLossDto;
import cn.ysk.cashier.dto.product.TbProductStockCountQueryCriteria;
import cn.ysk.cashier.dto.rabbit.StockRecordMsg;
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
import cn.ysk.cashier.dto.product.TbProductStockDetailDto;
import cn.ysk.cashier.dto.product.TbProductStockDetailQueryCriteria;
import cn.ysk.cashier.pojo.product.TbProductStockDetail;
import cn.ysk.cashier.vo.TbProductStockCountVo;
import org.springframework.data.domain.Pageable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
/**
* @website https://eladmin.vip
* @description 服务接口
* @author lyf
* @date 2024-01-19
**/
public interface TbProductStockDetailService {
/**
@ -33,7 +24,7 @@ public interface TbProductStockDetailService {
*/
Map<String,Object> queryAll(TbProductStockDetailQueryCriteria criteria, Pageable pageable);
Map<String,Object> queryPage(TbProductStockDetailQueryCriteria criteria);
Map<String,Object> queryPage(TbProductStockDetailQueryCriteria criteria) throws ParseException;
TbProductStockCountVo stockCount(TbProductStockCountQueryCriteria criteria) throws ParseException;
Map<String,Object> stockList(TbProductStockCountQueryCriteria criteria) throws ParseException;
@ -51,8 +42,6 @@ public interface TbProductStockDetailService {
*/
TbProductStockDetailDto findById(Long id);
HashMap<String, BigDecimal> sumStockNumber(String productId);
void frmLoss(TbProductFrmLossDto resources);
/**
* 创建