| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.aftersalesservice.dto.AfterSalesNearExpiryImportDto; |
| | | import com.ruoyi.aftersalesservice.mapper.AfterSalesNearExpiryMapper; |
| | | import com.ruoyi.aftersalesservice.pojo.AfterSalesNearExpiry; |
| | | import com.ruoyi.aftersalesservice.service.AfterSalesNearExpiryService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <br> |
| | |
| | | * @version 1.0 |
| | | * @since 2026/03/02 14:46 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class AfterSalesNearExpiryServiceImpl extends ServiceImpl<AfterSalesNearExpiryMapper, AfterSalesNearExpiry> implements AfterSalesNearExpiryService { |
| | | |
| | |
| | | public IPage<AfterSalesNearExpiry> listPage(Page<AfterSalesNearExpiry> page, AfterSalesNearExpiry entity) { |
| | | return baseMapper.listPage(page, entity); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult importData(MultipartFile file) { |
| | | List<AfterSalesNearExpiryImportDto> rows; |
| | | try { |
| | | ExcelUtil<AfterSalesNearExpiryImportDto> util = new ExcelUtil<>(AfterSalesNearExpiryImportDto.class); |
| | | rows = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | log.error("临期售后管理导入-解析excel失败", e); |
| | | return AjaxResult.error("解析Excel失败:" + e.getMessage()); |
| | | } |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return AjaxResult.error("导入文件无数据"); |
| | | } |
| | | int success = 0; |
| | | List<String> errors = new ArrayList<>(); |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | AfterSalesNearExpiryImportDto row = rows.get(i); |
| | | int rowNo = i + 2; // 首行为表头 |
| | | try { |
| | | if (StringUtils.isEmpty(trim(row.getProductName()))) { |
| | | errors.add("第" + rowNo + "行:临期产品名称为空"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(trim(row.getBatchNumber()))) { |
| | | errors.add("第" + rowNo + "行:产品批号为空"); |
| | | continue; |
| | | } |
| | | if (row.getExpireDate() == null) { |
| | | errors.add("第" + rowNo + "行:临期日期为空"); |
| | | continue; |
| | | } |
| | | if (row.getStockQuantity() == null) { |
| | | errors.add("第" + rowNo + "行:库存数量为空"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(trim(row.getCustomerName()))) { |
| | | errors.add("第" + rowNo + "行:客户名称为空"); |
| | | continue; |
| | | } |
| | | |
| | | AfterSalesNearExpiry entity = new AfterSalesNearExpiry(); |
| | | entity.setProductName(trim(row.getProductName())); |
| | | entity.setBatchNumber(trim(row.getBatchNumber())); |
| | | entity.setExpireDate(row.getExpireDate()); |
| | | entity.setStockQuantity(row.getStockQuantity()); |
| | | entity.setCustomerName(trim(row.getCustomerName())); |
| | | entity.setContactPhone(trim(row.getContactPhone())); |
| | | entity.setDisRes(row.getDisRes()); |
| | | |
| | | add(entity); |
| | | success++; |
| | | } catch (Exception e) { |
| | | log.error("临期售后管理导入第{}行失败", rowNo, e); |
| | | errors.add("第" + rowNo + "行:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | AjaxResult result = AjaxResult.success(); |
| | | result.put("totalCount", rows.size()); |
| | | result.put("successCount", success); |
| | | result.put("failCount", rows.size() - success); |
| | | result.put("errors", errors); |
| | | result.put("msg", "导入完成:成功 " + success + " 条,失败 " + (rows.size() - success) + " 条"); |
| | | return result; |
| | | } |
| | | |
| | | private String trim(String value) { |
| | | return value == null ? null : value.trim(); |
| | | } |
| | | } |