zepengdev
2025-06-14 6e0a83c55db4bae4d23a4c281946bda1d610f678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.oying.modules.pc.product.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.modules.pc.product.domain.Product;
import com.oying.modules.pc.product.domain.dto.ProductQueryCriteria;
import com.oying.modules.pc.product.mapper.ProductMapper;
import com.oying.modules.pc.product.service.ProductService;
import com.oying.utils.FileUtil;
import com.oying.utils.PageResult;
import com.oying.utils.PageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author lzp
 * @description 服务实现
 * @date 2025-04-30
 **/
@Service
@RequiredArgsConstructor
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
 
    private final ProductMapper productMapper;
 
    @Override
    public PageResult<Product> queryAll(ProductQueryCriteria criteria, Page<Object> page) {
        return PageUtil.toPage(productMapper.findAll(criteria, page));
    }
 
    @Override
    public List<Product> queryAll(ProductQueryCriteria criteria) {
        return productMapper.findAll(criteria);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(Product resources) {
        productMapper.insert(resources);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Product resources) {
        Product product = getById(resources.getProductId());
        product.copy(resources);
        productMapper.updateById(product);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        for (Long id : ids) {
            LambdaUpdateWrapper<Product> wrapper = new LambdaUpdateWrapper<Product>()
                    .eq(Product::getProductId, id)
                    .set(Product::getDeletedFlag, 1);
            // set状态
            this.update(wrapper);
        }
    }
 
    @Override
    public void download(List<Product> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (Product product : all) {
            Map<String, Object> map = new LinkedHashMap<>();
            map.put("商品编号", product.getStoreId());
            map.put("条形码", product.getBarcode());
            map.put("商品名称", product.getName());
            map.put("商品标题", product.getTitle());
            map.put("分类ID", product.getCategoryId());
            map.put("状态", product.getStatus());
            map.put("主图片", product.getMainImageId());
            map.put("主图地址", product.getMainImageUrl());
            map.put("商品描述", product.getDescription());
            map.put("销售价格", product.getPrice());
            map.put("库存数量", product.getStockQuantity());
            map.put("起售数量", product.getMinPurchaseQuantity());
            map.put("预警库存", product.getWarnStock());
            map.put("重量(单位:g)", product.getWeight());
            map.put("宽度(单位:厘米)", product.getWidth());
            map.put("长度(单位:厘米)", product.getLength());
            map.put("高度(单位:厘米)", product.getHeight());
            map.put("是否删除", product.getDeletedFlag());
            map.put("创建人", product.getCreateBy());
            map.put("创建时间", product.getCreateTime());
            map.put("修改人", product.getUpdateBy());
            map.put("修改时间", product.getUpdateTime());
            map.put("版本号", product.getVersion());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}