Kaynağa Gözat

商家pc端-运动健身

qrs 1 hafta önce
ebeveyn
işleme
5e8e048975

+ 5 - 5
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StoreMenuPlatformController.java

@@ -11,6 +11,7 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreMenu;
 import shop.alien.entity.store.vo.StoreMenuVo;
 import shop.alien.storeplatform.service.StoreMenuPlatformService;
+import shop.alien.storeplatform.vo.ExcelImportVo;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
@@ -129,11 +130,10 @@ public class StoreMenuPlatformController {
             @ApiImplicitParam(name = "file", value = "Excel文件", dataType = "file", paramType = "form", required = true),
             @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)
     })
-    @GetMapping("/importMenu")
-    public R<String> importMenu(@RequestParam("file") MultipartFile file,
-                                @RequestParam("storeId") Integer storeId) {
-        log.info("StoreMenuPlatformController.importMenu?storeId={}", storeId);
-        return storeMenuService.importMenuFromExcel(file, storeId);
+    @PostMapping("/importMenu")
+    public R<String> importMenu(ExcelImportVo vo) {
+        log.info("StoreMenuPlatformController.importMenu?storeId={}", vo.getStoreId());
+        return storeMenuService.importMenuFromExcel(vo.getFile(), vo.getStoreId());
     }
 
     @ApiOperation("下载美食导入模板")

+ 5 - 5
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformBarMenuController.java

@@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
 import shop.alien.entity.result.R;
 import shop.alien.storeplatform.entity.StorePlatformStoreMenu;
 import shop.alien.storeplatform.service.StorePlatformBarMenuService;
+import shop.alien.storeplatform.vo.ExcelImportVo;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
@@ -128,11 +129,10 @@ public class StorePlatformBarMenuController {
             @ApiImplicitParam(name = "file", value = "Excel文件", dataType = "file", paramType = "form", required = true),
             @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)
     })
-    @GetMapping("/importMenu")
-    public R<String> importMenu(@RequestParam("file") MultipartFile file,
-                                @RequestParam("storeId") Integer storeId) {
-        log.info("StorePlatformBarMenuController.importMenu storeId={}", storeId);
-        return barMenuService.importMenuFromExcel(file, storeId);
+    @PostMapping("/importMenu")
+    public R<String> importMenu(ExcelImportVo vo) {
+        log.info("StorePlatformBarMenuController.importMenu storeId={}", vo.getStoreId());
+        return barMenuService.importMenuFromExcel(vo.getFile(), vo.getStoreId());
     }
 
     @ApiOperation("下载酒水餐食导入模板")

+ 187 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformSportsEquipmentFacilityController.java

@@ -0,0 +1,187 @@
+package shop.alien.storeplatform.controller;
+
+import io.swagger.annotations.*;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import shop.alien.entity.result.R;
+import shop.alien.storeplatform.entity.StorePlatformSportsEquipmentFacility;
+import shop.alien.storeplatform.service.StorePlatformSportsEquipmentFacilityService;
+import shop.alien.storeplatform.vo.ExcelImportVo;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * 商户平台-运动器材设施Controller
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Api(tags = {"商户平台-运动健身"})
+@ApiSort(1)
+@CrossOrigin
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/storePlatformSportsEquipmentFacility")
+public class StorePlatformSportsEquipmentFacilityController {
+
+    private final StorePlatformSportsEquipmentFacilityService facilityService;
+
+    @ApiOperation("根据ID查询设施")
+    @ApiOperationSupport(order = 1)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "设施ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getById")
+    public R<StorePlatformSportsEquipmentFacility> getById(@RequestParam("id") Integer id) {
+        log.info("StorePlatformSportsEquipmentFacilityController.getById id={}", id);
+        StorePlatformSportsEquipmentFacility facility = facilityService.getById(id);
+        if (facility == null) {
+            return R.fail("设施不存在");
+        }
+        return R.data(facility);
+    }
+
+    @ApiOperation("根据门店ID查询设施列表")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getListByStoreId")
+    public R<List<StorePlatformSportsEquipmentFacility>> getListByStoreId(@RequestParam("storeId") Integer storeId) {
+        log.info("StorePlatformSportsEquipmentFacilityController.getListByStoreId storeId={}", storeId);
+        List<StorePlatformSportsEquipmentFacility> list = facilityService.getListByStoreId(storeId);
+        return R.data(list);
+    }
+
+    @ApiOperation("根据门店ID和设施分类查询设施列表")
+    @ApiOperationSupport(order = 3)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "facilityCategory", value = "设施分类(1:有氧区, 2:力量区, 3:单功能机械区)", dataType = "Integer", paramType = "query")
+    })
+    @GetMapping("/getListByStoreIdAndCategory")
+    public R<List<StorePlatformSportsEquipmentFacility>> getListByStoreIdAndCategory(@RequestParam("storeId") Integer storeId,
+                                                                                     @RequestParam(value = "facilityCategory", required = false) Integer facilityCategory) {
+        log.info("StorePlatformSportsEquipmentFacilityController.getListByStoreIdAndCategory storeId={}, facilityCategory={}", storeId, facilityCategory);
+        List<StorePlatformSportsEquipmentFacility> list = facilityService.getListByStoreIdAndCategory(storeId, facilityCategory);
+        return R.data(list);
+    }
+
+    @ApiOperation("新增设施")
+    @ApiOperationSupport(order = 4)
+    @PostMapping("/save")
+    public R<String> save(@RequestBody StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityController.save facility={}", facility);
+        return facilityService.saveFacility(facility);
+    }
+
+    @ApiOperation("修改设施")
+    @ApiOperationSupport(order = 5)
+    @PostMapping("/update")
+    public R<String> update(@RequestBody StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityController.update facility={}", facility);
+        return facilityService.updateFacility(facility);
+    }
+
+    @ApiOperation("新增或修改设施")
+    @ApiOperationSupport(order = 6)
+    @PostMapping("/saveOrUpdate")
+    public R<String> saveOrUpdate(@RequestBody StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityController.saveOrUpdate facility={}", facility);
+        return facilityService.saveOrUpdateFacility(facility);
+    }
+
+    @ApiOperation("删除设施")
+    @ApiOperationSupport(order = 7)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "设施ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/delete")
+    public R<String> delete(@RequestParam("id") Integer id) {
+        log.info("StorePlatformSportsEquipmentFacilityController.delete id={}", id);
+        return facilityService.deleteFacility(id);
+    }
+
+    @ApiOperation("批量删除设施")
+    @ApiOperationSupport(order = 8)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "ids", value = "设施ID列表", dataType = "List", paramType = "query", required = true)
+    })
+    @GetMapping("/deleteBatch")
+    public R<String> deleteBatch(@RequestParam("ids") List<Integer> ids) {
+        log.info("StorePlatformSportsEquipmentFacilityController.deleteBatch ids={}", ids);
+        return facilityService.deleteFacilityBatch(ids);
+    }
+
+    @ApiOperation("Excel导入运动健身设施")
+    @ApiOperationSupport(order = 9)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "file", value = "Excel文件", dataType = "file", paramType = "form", required = true),
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @PostMapping("/importFacility")
+    public R<String> importFacility(ExcelImportVo vo) {
+        log.info("StorePlatformSportsEquipmentFacilityController.importFacility storeId={}", vo.getStoreId());
+        return facilityService.importFacilityFromExcel(vo.getFile(), vo.getStoreId());
+    }
+
+    @ApiOperation("下载运动健身导入模板")
+    @ApiOperationSupport(order = 10)
+    @GetMapping("/downloadTemplate")
+    public void downloadTemplate(HttpServletResponse response) {
+        log.info("StoreMenuPlatformController.downloadTemplate");
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+
+        try {
+            // 从resources/templates目录读取模板文件
+            Resource resource = new ClassPathResource("templates/运动健身导入模板.xlsx");
+            inputStream = resource.getInputStream();
+
+            // 设置响应头
+            response.reset();
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+            response.setCharacterEncoding("utf-8");
+
+            String fileName = "运动健身导入模板.xlsx";
+            String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20");
+            response.setHeader("Content-Disposition", "attachment;filename=\"" + encodedFileName + "\";filename*=utf-8''" + encodedFileName);
+
+            // 输出文件流
+            outputStream = response.getOutputStream();
+            byte[] buffer = new byte[1024];
+            int length;
+            while ((length = inputStream.read(buffer)) > 0) {
+                outputStream.write(buffer, 0, length);
+            }
+            outputStream.flush();
+
+            log.info("运动健身导入模板下载成功");
+        } catch (Exception e) {
+            log.error("下载运动健身导入模板失败", e);
+            throw new RuntimeException("下载模板失败:" + e.getMessage());
+        } finally {
+            try {
+                if (inputStream != null) {
+                    inputStream.close();
+                }
+                if (outputStream != null) {
+                    outputStream.close();
+                }
+            } catch (Exception e) {
+                log.error("关闭流失败", e);
+            }
+        }
+    }
+}

+ 93 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformSportsEquipmentFacilityService.java

@@ -0,0 +1,93 @@
+package shop.alien.storeplatform.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.web.multipart.MultipartFile;
+import shop.alien.entity.result.R;
+import shop.alien.storeplatform.entity.StorePlatformSportsEquipmentFacility;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * 商户平台-运动器材设施服务类
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+public interface StorePlatformSportsEquipmentFacilityService extends IService<StorePlatformSportsEquipmentFacility> {
+
+    /**
+     * 根据ID查询设施
+     *
+     * @param id 设施ID
+     * @return 设施信息
+     */
+    StorePlatformSportsEquipmentFacility getById(Integer id);
+
+    /**
+     * 根据门店ID查询设施列表
+     *
+     * @param storeId 门店ID
+     * @return 设施列表
+     */
+    List<StorePlatformSportsEquipmentFacility> getListByStoreId(Integer storeId);
+
+    /**
+     * 根据门店ID和设施分类查询设施列表
+     *
+     * @param storeId         门店ID
+     * @param facilityCategory 设施分类(1:有氧区, 2:力量区, 3:单功能机械区)
+     * @return 设施列表
+     */
+    List<StorePlatformSportsEquipmentFacility> getListByStoreIdAndCategory(Integer storeId, Integer facilityCategory);
+
+    /**
+     * 新增设施
+     *
+     * @param facility 设施信息
+     * @return 操作结果
+     */
+    R<String> saveFacility(StorePlatformSportsEquipmentFacility facility);
+
+    /**
+     * 修改设施
+     *
+     * @param facility 设施信息
+     * @return 操作结果
+     */
+    R<String> updateFacility(StorePlatformSportsEquipmentFacility facility);
+
+    /**
+     * 新增或修改设施
+     *
+     * @param facility 设施信息
+     * @return 操作结果
+     */
+    R<String> saveOrUpdateFacility(StorePlatformSportsEquipmentFacility facility);
+
+    /**
+     * 删除设施(逻辑删除)
+     *
+     * @param id 设施ID
+     * @return 操作结果
+     */
+    R<String> deleteFacility(Integer id);
+
+    /**
+     * 批量删除设施(逻辑删除)
+     *
+     * @param ids 设施ID列表
+     * @return 操作结果
+     */
+    R<String> deleteFacilityBatch(List<Integer> ids);
+
+    /**
+     * Excel导入运动健身设施
+     *
+     * @param file     Excel文件
+     * @param storeId  门店id
+     * @return 导入结果
+     */
+    R<String> importFacilityFromExcel(MultipartFile file, Integer storeId);
+}

+ 430 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformSportsEquipmentFacilityServiceImpl.java

@@ -0,0 +1,430 @@
+package shop.alien.storeplatform.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import shop.alien.entity.result.R;
+import shop.alien.storeplatform.entity.StorePlatformSportsEquipmentFacility;
+import shop.alien.storeplatform.mapper.StorePlatformSportsEquipmentFacilityMapper;
+import shop.alien.storeplatform.service.StorePlatformSportsEquipmentFacilityService;
+import shop.alien.storeplatform.vo.StorePlatformSportsEquipmentFacilityImportVo;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 商户平台-运动器材设施服务实现类
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class StorePlatformSportsEquipmentFacilityServiceImpl extends ServiceImpl<StorePlatformSportsEquipmentFacilityMapper, StorePlatformSportsEquipmentFacility> implements StorePlatformSportsEquipmentFacilityService {
+
+    private final StorePlatformSportsEquipmentFacilityMapper facilityMapper;
+
+    @Override
+    public StorePlatformSportsEquipmentFacility getById(Integer id) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.getById id={}", id);
+        if (id == null) {
+            throw new RuntimeException("设施ID不能为空");
+        }
+        return super.getById(id);
+    }
+
+    @Override
+    public List<StorePlatformSportsEquipmentFacility> getListByStoreId(Integer storeId) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.getListByStoreId storeId={}", storeId);
+        if (storeId == null) {
+            throw new RuntimeException("门店ID不能为空");
+        }
+        LambdaQueryWrapper<StorePlatformSportsEquipmentFacility> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StorePlatformSportsEquipmentFacility::getStoreId, storeId)
+                .eq(StorePlatformSportsEquipmentFacility::getDeleteFlag, 0)
+                .orderByAsc(StorePlatformSportsEquipmentFacility::getFacilityCategory)
+                .orderByAsc(StorePlatformSportsEquipmentFacility::getId);
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public List<StorePlatformSportsEquipmentFacility> getListByStoreIdAndCategory(Integer storeId, Integer facilityCategory) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.getListByStoreIdAndCategory storeId={}, facilityCategory={}", storeId, facilityCategory);
+        if (storeId == null) {
+            throw new RuntimeException("门店ID不能为空");
+        }
+        LambdaQueryWrapper<StorePlatformSportsEquipmentFacility> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StorePlatformSportsEquipmentFacility::getStoreId, storeId)
+                .eq(StorePlatformSportsEquipmentFacility::getDeleteFlag, 0);
+        if (facilityCategory != null) {
+            queryWrapper.eq(StorePlatformSportsEquipmentFacility::getFacilityCategory, facilityCategory);
+        }
+        queryWrapper.orderByAsc(StorePlatformSportsEquipmentFacility::getFacilityCategory)
+                .orderByAsc(StorePlatformSportsEquipmentFacility::getId);
+        return this.list(queryWrapper);
+    }
+
+    @Override
+    public R<String> saveFacility(StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.saveFacility facility={}", facility);
+        if (facility == null) {
+            return R.fail("设施信息不能为空");
+        }
+        if (facility.getStoreId() == null) {
+            return R.fail("门店ID不能为空");
+        }
+        if (StringUtils.isEmpty(facility.getFacilityName())) {
+            return R.fail("设施名称不能为空");
+        }
+        if (facility.getFacilityCategory() == null) {
+            return R.fail("设施分类不能为空");
+        }
+        if (facility.getQuantity() == null || facility.getQuantity() <= 0) {
+            return R.fail("数量必须大于0");
+        }
+
+        boolean flag = this.save(facility);
+        if (!flag) {
+            return R.fail("新增设施失败");
+        }
+        return R.success("新增设施成功");
+    }
+
+    @Override
+    public R<String> updateFacility(StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.updateFacility facility={}", facility);
+        if (facility == null || facility.getId() == null) {
+            return R.fail("设施信息或设施ID不能为空");
+        }
+        if (StringUtils.isEmpty(facility.getFacilityName())) {
+            return R.fail("设施名称不能为空");
+        }
+        if (facility.getFacilityCategory() == null) {
+            return R.fail("设施分类不能为空");
+        }
+        if (facility.getQuantity() == null || facility.getQuantity() <= 0) {
+            return R.fail("数量必须大于0");
+        }
+
+        boolean flag = this.updateById(facility);
+        if (!flag) {
+            return R.fail("修改设施失败");
+        }
+        return R.success("修改设施成功");
+    }
+
+    @Override
+    public R<String> saveOrUpdateFacility(StorePlatformSportsEquipmentFacility facility) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.saveOrUpdateFacility facility={}", facility);
+        if (facility == null) {
+            return R.fail("设施信息不能为空");
+        }
+
+        if (facility.getId() != null) {
+            // 修改
+            return updateFacility(facility);
+        } else {
+            // 新增
+            return saveFacility(facility);
+        }
+    }
+
+    @Override
+    public R<String> deleteFacility(Integer id) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.deleteFacility id={}", id);
+        if (id == null) {
+            return R.fail("设施ID不能为空");
+        }
+
+        boolean flag = this.removeById(id);
+        if (!flag) {
+            return R.fail("删除设施失败");
+        }
+        return R.success("删除设施成功");
+    }
+
+    @Override
+    public R<String> deleteFacilityBatch(List<Integer> ids) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.deleteFacilityBatch ids={}", ids);
+        if (CollectionUtil.isEmpty(ids)) {
+            return R.fail("设施ID列表不能为空");
+        }
+
+        boolean flag = this.removeByIds(ids);
+        if (!flag) {
+            return R.fail("批量删除设施失败");
+        }
+        return R.success("批量删除设施成功");
+    }
+
+    @Override
+    public R<String> importFacilityFromExcel(MultipartFile file, Integer storeId) {
+        log.info("StorePlatformSportsEquipmentFacilityServiceImpl.importFacilityFromExcel storeId={}", storeId);
+
+        if (file == null || file.isEmpty()) {
+            return R.fail("上传文件为空");
+        }
+
+        String fileName = file.getOriginalFilename();
+        if (fileName == null || (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls"))) {
+            return R.fail("文件格式不正确,请上传Excel文件");
+        }
+
+        if (storeId == null) {
+            return R.fail("门店ID不能为空");
+        }
+
+        List<String> errorMessages = new ArrayList<>();
+        int successCount = 0;
+        int totalCount = 0;
+
+        try (InputStream inputStream = file.getInputStream();
+             XSSFWorkbook workbook = new XSSFWorkbook(inputStream)) {
+            Sheet sheet = workbook.getSheetAt(0);
+
+            // 获取表头(假设表头在第5行,索引为5)
+            Row headerRow = sheet.getRow(5);
+            if (headerRow == null) {
+                return R.fail("Excel文件格式不正确,缺少表头");
+            }
+
+            // 构建字段映射(表头名称 -> 列索引)
+            Map<String, Integer> headerMap = new HashMap<>();
+            Field[] fields = StorePlatformSportsEquipmentFacilityImportVo.class.getDeclaredFields();
+            for (int i = 0; i < headerRow.getLastCellNum(); i++) {
+                Cell cell = headerRow.getCell(i);
+                if (cell != null) {
+                    String headerName = getCellValueAsString(cell);
+                    if (StringUtils.isNotEmpty(headerName)) {
+                        headerMap.put(headerName.trim(), i);
+                    }
+                }
+            }
+
+            // 读取数据行(从第6行开始,索引为6)
+            for (int rowIndex = 6; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
+                Row row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+
+                // 检查是否为空行
+                boolean isEmptyRow = true;
+                for (int i = 0; i < row.getLastCellNum(); i++) {
+                    Cell cell = row.getCell(i);
+                    if (cell != null && cell.getCellType() != CellType.BLANK) {
+                        String cellValue = getCellValueAsString(cell);
+                        if (StringUtils.isNotEmpty(cellValue)) {
+                            isEmptyRow = false;
+                            break;
+                        }
+                    }
+                }
+                if (isEmptyRow) {
+                    continue;
+                }
+
+                totalCount++;
+                StorePlatformSportsEquipmentFacilityImportVo excelVo = new StorePlatformSportsEquipmentFacilityImportVo();
+
+                // 读取每个字段
+                for (Field field : fields) {
+                    field.setAccessible(true);
+                    String fieldName = field.getName();
+                    Integer colIndex = null;
+
+                    // 根据字段名查找对应的表头
+                    for (Map.Entry<String, Integer> entry : headerMap.entrySet()) {
+                        String headerName = entry.getKey();
+                        if (isFieldMatch(fieldName, headerName)) {
+                            colIndex = entry.getValue();
+                            break;
+                        }
+                    }
+
+                    if (colIndex == null) {
+                        continue;
+                    }
+
+                    Cell cell = row.getCell(colIndex);
+                    if (cell == null) {
+                        continue;
+                    }
+
+                    try {
+                        // 处理普通字段
+                        String cellValue = getCellValueAsString(cell);
+                        if (StringUtils.isNotEmpty(cellValue)) {
+                            setFieldValue(excelVo, field, cellValue.trim());
+                        }
+                    } catch (Exception e) {
+                        log.warn("读取字段{}失败:{}", fieldName, e.getMessage());
+                    }
+                }
+
+                // 处理导入数据
+                try {
+                    validateAndSaveFacility(excelVo, storeId, rowIndex + 1);
+                    successCount++;
+                } catch (Exception e) {
+                    errorMessages.add(String.format("第%d行:%s", rowIndex + 1, e.getMessage()));
+                    log.error("导入第{}行数据失败", rowIndex + 1, e);
+                }
+            }
+        } catch (Exception e) {
+            log.error("导入Excel失败", e);
+            return R.fail("导入失败:" + e.getMessage());
+        }
+
+        // 构建返回消息
+        StringBuilder message = new StringBuilder();
+        message.append(String.format("导入完成:成功%d条,失败%d条", successCount, totalCount - successCount));
+        if (!errorMessages.isEmpty()) {
+            message.append("\n失败详情:\n");
+            for (int i = 0; i < Math.min(errorMessages.size(), 10); i++) {
+                message.append(errorMessages.get(i)).append("\n");
+            }
+            if (errorMessages.size() > 10) {
+                message.append("...还有").append(errorMessages.size() - 10).append("条错误信息");
+            }
+        }
+
+        return R.success(message.toString());
+    }
+
+    /**
+     * 判断字段名是否匹配表头
+     */
+    private boolean isFieldMatch(String fieldName, String headerName) {
+        Map<String, String> fieldMapping = new HashMap<>();
+        fieldMapping.put("facilityCategory", "分类(有氧区/力量区/单功能机械区)");
+        fieldMapping.put("facilityName", "设施名称");
+        fieldMapping.put("quantity", "数量");
+        fieldMapping.put("brand", "品牌");
+        fieldMapping.put("description", "描述");
+        fieldMapping.put("displayInStoreDetail", "展示在店铺详情(展示/隐藏)");
+
+        String expectedHeader = fieldMapping.get(fieldName);
+        return expectedHeader != null && expectedHeader.equals(headerName);
+    }
+
+    /**
+     * 设置字段值
+     */
+    private void setFieldValue(StorePlatformSportsEquipmentFacilityImportVo excelVo, Field field, String cellValue) throws Exception {
+        Class<?> fieldType = field.getType();
+        String fieldName = field.getName();
+
+        if (fieldType == Integer.class) {
+            if ("facilityCategory".equals(fieldName)) {
+                // 处理设施分类:有氧区->1, 力量区->2, 单功能机械区->3
+                String trimmedValue = cellValue.trim();
+                if ("有氧区".equals(trimmedValue)) {
+                    field.set(excelVo, 1);
+                } else if ("力量区".equals(trimmedValue)) {
+                    field.set(excelVo, 2);
+                } else if ("单功能机械区".equals(trimmedValue)) {
+                    field.set(excelVo, 3);
+                } else {
+                    throw new RuntimeException("设施分类格式错误,请输入'有氧区'、'力量区'或'单功能机械区'");
+                }
+            } else if ("displayInStoreDetail".equals(fieldName)) {
+                // 处理是否显示在店铺详情:是->1, 否->0
+                String trimmedValue = cellValue.trim();
+                if ("展示".equals(trimmedValue)) {
+                    field.set(excelVo, 1);
+                } else if ("隐藏".equals(trimmedValue)) {
+                    field.set(excelVo, 0);
+                } else {
+                    throw new RuntimeException("是否显示在店铺详情字段格式错误,请输入'是'或'否'");
+                }
+            } else {
+                // 其他Integer字段直接解析
+                try {
+                    field.set(excelVo, Integer.parseInt(cellValue));
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException(fieldName + "字段格式错误,请输入数字");
+                }
+            }
+        } else {
+            // String类型
+            field.set(excelVo, cellValue);
+        }
+    }
+
+    /**
+     * 校验并保存设施
+     */
+    private void validateAndSaveFacility(StorePlatformSportsEquipmentFacilityImportVo excelVo, Integer storeId, int rowNum) {
+        // 校验必填字段
+        if (StringUtils.isEmpty(excelVo.getFacilityName())) {
+            throw new RuntimeException("设施名称不能为空");
+        }
+        if (excelVo.getFacilityCategory() == null) {
+            throw new RuntimeException("设施分类不能为空");
+        }
+        if (excelVo.getQuantity() == null || excelVo.getQuantity() <= 0) {
+            throw new RuntimeException("数量必须大于0");
+        }
+
+        // 创建StorePlatformSportsEquipmentFacility对象
+        StorePlatformSportsEquipmentFacility facility = new StorePlatformSportsEquipmentFacility();
+        facility.setStoreId(storeId);
+        facility.setFacilityCategory(excelVo.getFacilityCategory());
+        facility.setFacilityName(excelVo.getFacilityName());
+        facility.setQuantity(excelVo.getQuantity());
+        facility.setBrand(excelVo.getBrand());
+        facility.setDescription(excelVo.getDescription());
+        facility.setDisplayInStoreDetail(excelVo.getDisplayInStoreDetail() != null ? excelVo.getDisplayInStoreDetail() : 0);
+
+        // 保存设施
+        boolean flag = this.save(facility);
+        if (!flag) {
+            throw new RuntimeException("保存设施失败");
+        }
+    }
+
+    /**
+     * 获取单元格值(字符串格式)
+     */
+    private String getCellValueAsString(Cell cell) {
+        if (cell == null) {
+            return null;
+        }
+
+        switch (cell.getCellType()) {
+            case STRING:
+                return cell.getStringCellValue();
+            case NUMERIC:
+                if (DateUtil.isCellDateFormatted(cell)) {
+                    return cell.getDateCellValue().toString();
+                } else {
+                    // 处理数字,避免科学计数法
+                    double numericValue = cell.getNumericCellValue();
+                    if (numericValue == (long) numericValue) {
+                        return String.valueOf((long) numericValue);
+                    } else {
+                        return String.valueOf(numericValue);
+                    }
+                }
+            case BOOLEAN:
+                return String.valueOf(cell.getBooleanCellValue());
+            case FORMULA:
+                return cell.getCellFormula();
+            default:
+                return null;
+        }
+    }
+}

+ 13 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/vo/ExcelImportVo.java

@@ -0,0 +1,13 @@
+package shop.alien.storeplatform.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
+
+@Data
+@JsonInclude
+public class ExcelImportVo {
+    private MultipartFile file;
+
+    private Integer storeId;
+}

BIN
alien-store-platform/src/main/resources/templates/运动健身导入模板.xlsx