| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.sales.dto.LossProductModelDto; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult importProductModel(MultipartFile file, Integer productId) { |
| | | public R<?> importProductModel(MultipartFile file, Integer productId) { |
| | | if (productId == null) { |
| | | return AjaxResult.error("请先选择产品再导入规格型号"); |
| | | return R.fail("请先选择产品再导入规格型号"); |
| | | } |
| | | |
| | | Product product = productMapper.selectById(productId); |
| | | if (product == null) { |
| | | return AjaxResult.error("选择的产品不存在"); |
| | | return R.fail("选择的产品不存在"); |
| | | } |
| | | |
| | | try { |
| | |
| | | List<ProductModel> productModelList = productModelExcelUtil.importExcel(file.getInputStream()); |
| | | |
| | | if (CollectionUtils.isEmpty(productModelList)) { |
| | | return AjaxResult.error("导入数据不能为空"); |
| | | return R.fail("导入数据不能为空"); |
| | | } |
| | | |
| | | // 获取当前产品下所有的规格型号名 |
| | |
| | | int rowNum = i + 2; |
| | | |
| | | if (StringUtils.isEmpty(item.getProductCode())) { |
| | | return AjaxResult.error("第 " + rowNum + " 行导入失败: [产品编码] 不能为空"); |
| | | return R.fail("第 " + rowNum + " 行导入失败: [产品编码] 不能为空"); |
| | | } |
| | | if (StringUtils.isEmpty(item.getModel())) { |
| | | return AjaxResult.error("第 " + rowNum + " 行导入失败: [规格型号] 不能为空"); |
| | | return R.fail("第 " + rowNum + " 行导入失败: [规格型号] 不能为空"); |
| | | } |
| | | if (StringUtils.isEmpty(item.getUnit())) { |
| | | return AjaxResult.error("第 " + rowNum + " 行导入失败: [单位] 不能为空"); |
| | | return R.fail("第 " + rowNum + " 行导入失败: [单位] 不能为空"); |
| | | } |
| | | |
| | | // 去重,如果已包含该型号,则跳过 |
| | |
| | | } |
| | | |
| | | if (skipCount == 0) { |
| | | return AjaxResult.success(String.format("成功导入 %d 条数据", waitToSaveList.size())); |
| | | return R.ok(null, String.format("成功导入 %d 条数据", waitToSaveList.size())); |
| | | } else { |
| | | return AjaxResult.success(String.format("成功导入 %d 条,跳过已存在数据 %d 条", waitToSaveList.size(), skipCount)); |
| | | return R.ok(null, String.format("成功导入 %d 条,跳过已存在数据 %d 条", waitToSaveList.size(), skipCount)); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("导入产品规格异常", e); |