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);
|
}
|
}
|