商品列表 销量/库存展示
This commit is contained in:
parent
0e1833fe32
commit
2c5c32883d
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
* 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;
|
||||
|
|
@ -54,11 +54,11 @@ import java.util.stream.Collectors;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @author lyf
|
||||
* @date 2023-12-11
|
||||
**/
|
||||
* @author lyf
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @date 2023-12-11
|
||||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TbProductServiceImpl implements TbProductService {
|
||||
|
|
@ -74,11 +74,11 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(TbProductQueryCriteria criteria){
|
||||
public Map<String, Object> queryAll(TbProductQueryCriteria criteria) {
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), sort);
|
||||
//查询商品数据
|
||||
Page<TbProduct> page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
Page<TbProduct> page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
List<String> productId = new ArrayList<>();
|
||||
List<Integer> unitId = new ArrayList<>();
|
||||
List<Integer> specId = new ArrayList<>();
|
||||
|
|
@ -86,8 +86,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
//记录商品id
|
||||
productId.add(product.getId().toString());
|
||||
//记录单位id
|
||||
if (product.getUnitId() != null){
|
||||
if (!"".equals(product.getUnitId())){
|
||||
if (product.getUnitId() != null) {
|
||||
if (!"".equals(product.getUnitId())) {
|
||||
unitId.add(product.getUnitId());
|
||||
}
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(productId);
|
||||
//单位
|
||||
List<TbShopUnit> tbShopUnits = new ArrayList<>();
|
||||
if (!unitId.isEmpty()){
|
||||
if (!unitId.isEmpty()) {
|
||||
tbShopUnits = tbShopUnitRepository.searchUnit(unitId);
|
||||
}
|
||||
//商品规格
|
||||
|
|
@ -107,7 +107,7 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
tbProductSpecs = tbProductSpecRepository.searchSpec(specId);
|
||||
}
|
||||
//组装
|
||||
List<TbProductVo> tbProductVoList = new ArrayList<>();
|
||||
List<TbProductVo> tbProductVoList = new ArrayList<>();
|
||||
for (TbProduct product : page.getContent()) {
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
TbProductVo tbProductVo = new TbProductVo();
|
||||
|
|
@ -116,33 +116,33 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
Double stockNumber = 0.00;
|
||||
for (TbProductSku sku : tbProductSkus) {
|
||||
//sku
|
||||
if (sku.getProductId().equals(product.getId().toString())){
|
||||
if (sku.getProductId().equals(product.getId().toString())) {
|
||||
skuList.add(sku);
|
||||
realSalesNumber = realSalesNumber + sku.getRealSalesNumber();
|
||||
stockNumber = stockNumber + sku.getStockNumber();
|
||||
}
|
||||
realSalesNumber = realSalesNumber + sku.getRealSalesNumber();
|
||||
stockNumber = stockNumber + sku.getStockNumber();
|
||||
}
|
||||
tbProductVo.setRealSalesNumber(realSalesNumber);
|
||||
tbProductVo.setStockNumber(stockNumber);
|
||||
tbProductVo.setSkuList(skuList);
|
||||
//单位
|
||||
if (tbShopUnits.isEmpty()){
|
||||
if (tbShopUnits.isEmpty()) {
|
||||
tbProductVo.setUnitName("");
|
||||
}else {
|
||||
} else {
|
||||
for (TbShopUnit tbShopUnit : tbShopUnits) {
|
||||
if(tbShopUnit.getId().equals(product.getUnitId())){
|
||||
if (tbShopUnit.getId().equals(product.getUnitId())) {
|
||||
tbProductVo.setUnitName(tbShopUnit.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
//商品规格
|
||||
if (tbProductSpecs.isEmpty()){
|
||||
if (tbProductSpecs.isEmpty()) {
|
||||
tbProductVo.setSpecsInfo(new HashMap<>());
|
||||
}else {
|
||||
for (TbProductSpec spec :tbProductSpecs) {
|
||||
if (spec.getId().equals(product.getSpecId())){
|
||||
} else {
|
||||
for (TbProductSpec spec : tbProductSpecs) {
|
||||
if (spec.getId().equals(product.getSpecId())) {
|
||||
HashMap<String, String> specsMap = new HashMap<>();
|
||||
specsMap.put(spec.getName(),spec.getSpecList());
|
||||
specsMap.put(spec.getName(), spec.getSpecList());
|
||||
tbProductVo.setSpecsInfo(specsMap);
|
||||
}
|
||||
}
|
||||
|
|
@ -151,16 +151,16 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
BeanUtils.copyProperties(product, tbProductVo);
|
||||
tbProductVoList.add(tbProductVo);
|
||||
}
|
||||
return PageUtil.toPage(tbProductVoList,page.getTotalElements());
|
||||
return PageUtil.toPage(tbProductVoList, page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbProductVo findByProductId(Integer id) throws Exception{
|
||||
public TbProductVo findByProductId(Integer id) throws Exception {
|
||||
TbProduct tbProduct = tbProductRepository.findById(id).orElseGet(TbProduct::new);
|
||||
|
||||
//单位
|
||||
CompletableFuture<TbShopUnit> tbShopUnits = CompletableFuture.supplyAsync(() ->
|
||||
tbShopUnitRepository.searchUnit(Integer.valueOf(StringUtils.isEmpty(tbProduct.getUnitId())? null:tbProduct.getUnitId() )));
|
||||
tbShopUnitRepository.searchUnit(Integer.valueOf(StringUtils.isEmpty(tbProduct.getUnitId()) ? null : tbProduct.getUnitId())));
|
||||
//sku
|
||||
CompletableFuture<List<TbProductSku>> tbProductSkus = CompletableFuture.supplyAsync(() ->
|
||||
tbProductSkuRepository.searchSku(tbProduct.getId().toString()));
|
||||
|
|
@ -168,19 +168,19 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
CompletableFuture<TbProductSpec> tbProductSpec = CompletableFuture.supplyAsync(() ->
|
||||
tbProductSpecRepository.searchSpec(tbProduct.getSpecId()));
|
||||
|
||||
Threads.call(tbShopUnits,tbProductSkus,tbProductSpec);
|
||||
Threads.call(tbShopUnits, tbProductSkus, tbProductSpec);
|
||||
//组装
|
||||
TbProductVo tbProductVo = new TbProductVo();
|
||||
tbProductVo.setCategoryId(Integer.valueOf(tbProduct.getCategoryId()));
|
||||
//单位
|
||||
if (tbProduct.getUnitId() == null){
|
||||
if (tbProduct.getUnitId() == null) {
|
||||
tbProductVo.setUnitId(null);
|
||||
tbProductVo.setUnitName(null);
|
||||
}
|
||||
//套餐
|
||||
if (tbProduct.getGroupSnap() == null){
|
||||
if (tbProduct.getGroupSnap() == null) {
|
||||
tbProductVo.setGroupSnap(new JSONArray());
|
||||
}else {
|
||||
} else {
|
||||
tbProductVo.setGroupSnap(ListUtil.stringChangeList(tbProduct.getGroupSnap()));
|
||||
}
|
||||
BeanUtils.copyProperties(tbProduct, tbProductVo);
|
||||
|
|
@ -189,16 +189,16 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
//商品规格
|
||||
if (tbProductSpec.get() == null){
|
||||
if (tbProductSpec.get() == null) {
|
||||
tbProductVo.setSpecsInfo(map);
|
||||
}else {
|
||||
map.put(tbProductSpec.get().getName(),tbProductSpec.get().getSpecList());
|
||||
} else {
|
||||
map.put(tbProductSpec.get().getName(), tbProductSpec.get().getSpecList());
|
||||
tbProductVo.setSpecsInfo(map);
|
||||
}
|
||||
//sku
|
||||
if (tbProductSkus.get() == null){
|
||||
if (tbProductSkus.get() == null) {
|
||||
tbProductVo.setSkuList(new ArrayList<>());
|
||||
}else {
|
||||
} else {
|
||||
tbProductVo.setSkuList(tbProductSkus.get());
|
||||
}
|
||||
return tbProductVo;
|
||||
|
|
@ -215,15 +215,15 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<TbProductDto> queryAlls(TbProductQueryCriteria criteria){
|
||||
return tbProductMapper.toDto(tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
public List<TbProductDto> queryAlls(TbProductQueryCriteria criteria) {
|
||||
return tbProductMapper.toDto(tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public TbProductDto findById(Integer id) {
|
||||
TbProduct tbProduct = tbProductRepository.findById(id).orElseGet(TbProduct::new);
|
||||
ValidationUtil.isNull(tbProduct.getId(),"TbProduct","id",id);
|
||||
ValidationUtil.isNull(tbProduct.getId(), "TbProduct", "id", id);
|
||||
return tbProductMapper.toDto(tbProduct);
|
||||
}
|
||||
|
||||
|
|
@ -233,13 +233,13 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
public Object create(TbProductVo resources) {
|
||||
TbProduct product = new TbProduct();
|
||||
//组装
|
||||
BeanUtil.copyProperties(resources,product, CopyOptions.create().setIgnoreNullValue(true));
|
||||
if (resources.getCategoryId() == null){
|
||||
BeanUtil.copyProperties(resources, product, CopyOptions.create().setIgnoreNullValue(true));
|
||||
if (resources.getCategoryId() == null) {
|
||||
throw new BadRequestException("必填内容未填写");
|
||||
}
|
||||
if (resources.getIsShowMall()==1){
|
||||
if (resources.getIsShowMall() == 1) {
|
||||
for (TbProductSku sku : resources.getSkuList()) {
|
||||
if(sku.getStockNumber()<=0){
|
||||
if (sku.getStockNumber() <= 0) {
|
||||
throw new BadRequestException("上架区域包括小程序时,库存数量必须大于0。");
|
||||
}
|
||||
}
|
||||
|
|
@ -252,19 +252,19 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
product.setStatus(1);
|
||||
product.setCreatedAt(Instant.now().toEpochMilli());
|
||||
product.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
if (!resources.getGroupSnap().isEmpty()){
|
||||
if (!resources.getGroupSnap().isEmpty()) {
|
||||
ListUtil.JSONArrayChangeString(resources.getGroupSnap());
|
||||
}
|
||||
if (resources.getUnitId() != null){
|
||||
if (resources.getUnitId() != null) {
|
||||
product.setUnitId(resources.getUnitId());
|
||||
}
|
||||
//套餐内容
|
||||
if (!resources.getGroupSnap().isEmpty()){
|
||||
if (!resources.getGroupSnap().isEmpty()) {
|
||||
product.setGroupSnap(ListUtil.JSONArrayChangeString(resources.getGroupSnap()));
|
||||
}
|
||||
TbProduct save = tbProductRepository.save(product);
|
||||
|
||||
if (save.getId() == null){
|
||||
if (save.getId() == null) {
|
||||
throw new BadRequestException("添加商品失败");
|
||||
}
|
||||
//sku
|
||||
|
|
@ -280,10 +280,10 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.saveAll(skuList);
|
||||
Map<Integer, Double> idStockMap = tbProductSkus.stream()
|
||||
.collect(Collectors.toMap(TbProductSku::getId, TbProductSku::getStockNumber));
|
||||
redisUtils.redisUp(1,save.getShopId(),idStockMap);
|
||||
redisUtils.redisUp(1, save.getShopId(), idStockMap);
|
||||
}
|
||||
//保存到sku_result
|
||||
if ("sku".equals(resources.getTypeEnum())){
|
||||
if ("sku".equals(resources.getTypeEnum())) {
|
||||
TbProductSkuResult productSkuResult = new TbProductSkuResult();
|
||||
productSkuResult.setCreatedAt(Instant.now().toEpochMilli());
|
||||
productSkuResult.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
|
|
@ -295,7 +295,6 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbProductVo resources) {
|
||||
|
|
@ -309,14 +308,14 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
product.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
product.setCategoryId(resources.getCategoryId().toString());
|
||||
product.setImages(resources.getImages().toString());
|
||||
if (!resources.getGroupSnap().isEmpty()){
|
||||
if (!resources.getGroupSnap().isEmpty()) {
|
||||
ListUtil.JSONArrayChangeString(resources.getGroupSnap());
|
||||
}
|
||||
TbProduct save = tbProductRepository.save(product);
|
||||
|
||||
//sku
|
||||
if (resources.getSkuList() != null) {
|
||||
if ("sku".equals(save.getTypeEnum())){
|
||||
if ("sku".equals(save.getTypeEnum())) {
|
||||
tbProductSkuRepository.deleteByProductId(String.valueOf(save.getId()));
|
||||
}
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
|
|
@ -330,7 +329,7 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
|
||||
}
|
||||
//保存到sku_result
|
||||
if ("sku".equals(resources.getTypeEnum())){
|
||||
if ("sku".equals(resources.getTypeEnum())) {
|
||||
TbProductSkuResult productSkuResult = new TbProductSkuResult();
|
||||
productSkuResult.setCreatedAt(Instant.now().toEpochMilli());
|
||||
productSkuResult.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
|
|
@ -345,11 +344,11 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
public void deleteAll(Integer[] ids) {
|
||||
List<Integer> list = Arrays.asList(ids);
|
||||
tbProductRepository.updateByStatus(list);
|
||||
list.forEach(productId->{
|
||||
list.forEach(productId -> {
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(productId.toString());
|
||||
Map<Integer, Double> idStockMap = tbProductSkus.stream()
|
||||
.collect(Collectors.toMap(TbProductSku::getId, TbProductSku::getStockNumber));
|
||||
redisUtils.redisUp(2,tbProductSkus.get(0).getShopId(),idStockMap);
|
||||
redisUtils.redisUp(2, tbProductSkus.get(0).getShopId(), idStockMap);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +356,7 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
public void download(List<TbProductDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (TbProductDto tbProduct : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("商品来源 NORMAL普通商品 --,SCORE积分商品", tbProduct.getSourcePath());
|
||||
map.put("商户Id", tbProduct.getMerchantId());
|
||||
map.put("店铺id", tbProduct.getShopId());
|
||||
|
|
@ -367,11 +366,11 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
map.put("商品最低价", tbProduct.getLowPrice());
|
||||
map.put("单位Id", tbProduct.getUnitId());
|
||||
map.put("商品封面图", tbProduct.getCoverImg());
|
||||
map.put(" categoryId", tbProduct.getCategoryId());
|
||||
map.put(" categoryId", tbProduct.getCategoryId());
|
||||
map.put("商品规格", tbProduct.getSpecId());
|
||||
map.put("品牌Id", tbProduct.getBrandId());
|
||||
map.put("短标题--促销语", tbProduct.getShortTitle());
|
||||
map.put(" lowMemberPrice", tbProduct.getLowMemberPrice());
|
||||
map.put(" lowMemberPrice", tbProduct.getLowMemberPrice());
|
||||
map.put("单位镜像", tbProduct.getUnitSnap());
|
||||
map.put("商品分享图", tbProduct.getShareImg());
|
||||
map.put("商品图片(第一张为缩略图,其他为详情)", tbProduct.getImages());
|
||||
|
|
@ -399,8 +398,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
map.put("vip专属", tbProduct.getIsVip());
|
||||
map.put("是否删除", tbProduct.getIsDelete());
|
||||
map.put("购买须知", tbProduct.getNotice());
|
||||
map.put(" createdAt", tbProduct.getCreatedAt());
|
||||
map.put(" updatedAt", tbProduct.getUpdatedAt());
|
||||
map.put(" createdAt", tbProduct.getCreatedAt());
|
||||
map.put(" updatedAt", tbProduct.getUpdatedAt());
|
||||
map.put("基础出售数量", tbProduct.getBaseSalesNumber());
|
||||
map.put("实际销量", tbProduct.getRealSalesNumber());
|
||||
map.put("合计销量", tbProduct.getSalesNumber());
|
||||
|
|
@ -412,8 +411,8 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
map.put("支持虚拟", tbProduct.getFurnishVir());
|
||||
map.put("是否套餐", tbProduct.getIsCombo());
|
||||
map.put("套餐内容", tbProduct.getGroupSnap());
|
||||
map.put(" isShowCash", tbProduct.getIsShowCash());
|
||||
map.put(" isShowMall", tbProduct.getIsShowMall());
|
||||
map.put(" isShowCash", tbProduct.getIsShowCash());
|
||||
map.put(" isShowMall", tbProduct.getIsShowMall());
|
||||
map.put("是否需要审核", tbProduct.getIsNeedExamine());
|
||||
map.put("线上商城展示状态0待审核 -1 异常 1正常", tbProduct.getShowOnMallStatus());
|
||||
map.put("提交审核时间", tbProduct.getShowOnMallTime());
|
||||
|
|
|
|||
Loading…
Reference in New Issue