| | |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | | import com.ruoyi.stock.dto.StockInRecordImportDto; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.execl.StockInRecordExportData; |
| | |
| | | import com.ruoyi.stock.service.StockInRecordService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockUninventoryMapper stockUninventoryMapper; |
| | | private ProductionOrderPickMapper productionOrderPickMapper; |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | @Override |
| | | public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) { |
| | |
| | | |
| | | return ids.size(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult importData(MultipartFile file, String type) { |
| | | List<StockInRecordImportDto> rows; |
| | | try { |
| | | ExcelUtil<StockInRecordImportDto> util = new ExcelUtil<>(StockInRecordImportDto.class); |
| | | rows = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | return AjaxResult.error("解析Excel失败:" + e.getMessage()); |
| | | } |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return AjaxResult.error("导入文件无数据"); |
| | | } |
| | | String stockType = StringUtils.isEmpty(type) ? "0" : type.trim(); |
| | | String recordType = "1".equals(stockType) |
| | | ? StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_IN.getCode() |
| | | : StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode(); |
| | | |
| | | int success = 0; |
| | | List<String> errors = new ArrayList<>(); |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | StockInRecordImportDto row = rows.get(i); |
| | | int rowNo = i + 2; // 首行为表头 |
| | | try { |
| | | String productName = trim(row.getProductName()); |
| | | String model = trim(row.getModel()); |
| | | if (StringUtils.isEmpty(productName)) { |
| | | errors.add("第" + rowNo + "行:产品大类为空"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(model)) { |
| | | errors.add("第" + rowNo + "行:规格型号为空"); |
| | | continue; |
| | | } |
| | | if (row.getStockInNum() == null) { |
| | | errors.add("第" + rowNo + "行:入库数量为空"); |
| | | continue; |
| | | } |
| | | ProductModel productModel = productModelMapper.selectByProductNameAndModel(productName, model); |
| | | if (productModel == null) { |
| | | errors.add("第" + rowNo + "行:未找到产品[" + productName + " / " + model + "]"); |
| | | continue; |
| | | } |
| | | StockInRecordDto dto = new StockInRecordDto(); |
| | | dto.setProductModelId(productModel.getId()); |
| | | dto.setBatchNo(trim(row.getBatchNo())); |
| | | dto.setStockInNum(row.getStockInNum()); |
| | | dto.setRemark(row.getRemark()); |
| | | dto.setType(stockType); |
| | | dto.setRecordType(recordType); |
| | | dto.setApprovalStatus(ReviewStatusEnum.PENDING_REVIEW.getCode()); |
| | | add(dto); |
| | | success++; |
| | | } catch (Exception 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(); |
| | | } |
| | | } |