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 com.oying.utils.SecurityUtils; 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 implements ProductService { private final ProductMapper productMapper; @Override public PageResult queryAll(ProductQueryCriteria criteria, Page page) { return PageUtil.toPage(productMapper.findAll(criteria, page)); } @Override public List queryAll(ProductQueryCriteria criteria) { return productMapper.findAll(criteria); } @Override @Transactional(rollbackFor = Exception.class) public void create(Product resources) { resources.setCreateBy(SecurityUtils.getCurrentUserId()); productMapper.insert(resources); } @Override @Transactional(rollbackFor = Exception.class) public void update(Product resources) { Product product = getById(resources.getProductId()); product.copy(resources); product.setUpdateBy(SecurityUtils.getCurrentUserId()); productMapper.updateById(product); } @Override @Transactional(rollbackFor = Exception.class) public void deleteAll(List ids) { for (Long id : ids) { LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() .eq(Product::getProductId, id) .set(Product::getDeletedFlag, 1); // set状态 this.update(wrapper); } } @Override public void download(List all, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); for (Product product : all) { Map 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("状态:1000-草稿 1001上架 1002下架", product.getStatus()); map.put("主图片", product.getMainImage()); map.put("详情图片", product.getDetailImage()); 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); } }