| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | /** |
| | | * 过磅记录(磅单台账)Controller |
| | |
| | | // 去重检查 |
| | | List<WeighingRecord> newRecordList = new ArrayList<>(); |
| | | int duplicateCount = 0; |
| | | int matchedCount = 0; |
| | | int unmatchedCount = 0; |
| | | |
| | | for (WeighingRecord record : weighingRecordList) { |
| | | LambdaQueryWrapper<WeighingRecord> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(WeighingRecord::getSerialNo, record.getSerialNo()); |
| | | |
| | | if (ObjectUtils.isEmpty(record.getSpecification())) { |
| | | record.setSpecification("/"); |
| | | } |
| | | long count = weighingRecordService.count(wrapper); |
| | | if (count == 0) { |
| | | newRecordList.add(record); |
| | |
| | | return R.fail("所有数据都已存在,共" + duplicateCount + "条重复数据"); |
| | | } |
| | | |
| | | // 批量插入新数据 |
| | | weighingRecordService.saveBatch(newRecordList); |
| | | // 批量插入新数据并执行出库操作 |
| | | for (WeighingRecord record : newRecordList) { |
| | | // 先保存磅单记录,获取ID |
| | | weighingRecordService.save(record); |
| | | |
| | | String message = String.format("导入成功:%d条,跳过重复:%d条", newRecordList.size(), duplicateCount); |
| | | |
| | | // 根据客户、产品名称、规格匹配销售台账并出库 |
| | | Long productId = weighingRecordService.matchAndOutStock( |
| | | record.getReceiveUnit(), // 收货单位=客户 |
| | | record.getGoodsName(), // 货名=产品名称 |
| | | record.getSpecification(), // 规格型号 |
| | | record.getNetWeight(), // 净重=数量 |
| | | record.getId() // 磅单ID作为关联记录ID |
| | | ); |
| | | if (productId != null) { |
| | | matchedCount++; |
| | | } else { |
| | | unmatchedCount++; |
| | | } |
| | | } |
| | | |
| | | String message = String.format("导入成功:%d条,跳过重复:%d条,匹配出库:%d条,未匹配:%d条", |
| | | newRecordList.size(), duplicateCount, matchedCount, unmatchedCount); |
| | | return R.ok(message); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("磅单导入失败:{}", e.getMessage()); |
| | | return R.fail("导入失败:" + e.getMessage()); |
| | | } |
| | | } |