| | |
| | | import com.ruoyi.basic.entity.CoalField; |
| | | import com.ruoyi.basic.entity.CoalInfo; |
| | | import com.ruoyi.basic.entity.CoalValue; |
| | | import com.ruoyi.basic.entity.Supply; |
| | | import com.ruoyi.basic.mapper.CoalFieldMapper; |
| | | import com.ruoyi.basic.mapper.CoalInfoMapper; |
| | | import com.ruoyi.basic.mapper.CoalValueMapper; |
| | | import com.ruoyi.basic.mapper.SupplyMapper; |
| | | import com.ruoyi.business.dto.OfficialInventoryDto; |
| | | import com.ruoyi.business.entity.OfficialInventory; |
| | | import com.ruoyi.business.mapper.OfficialInventoryMapper; |
| | |
| | | |
| | | private final CoalInfoMapper coalInfoMapper; |
| | | |
| | | private final SupplyMapper supplyMapper; |
| | | |
| | | |
| | | @Override |
| | | public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) { |
| | | |
| | | // 先查出原始数据(OfficialInventory) |
| | | LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByAsc(OfficialInventory::getCreateTime); |
| | | IPage<OfficialInventory> entityPage = officialInventoryMapper.selectPage(page, queryWrapper); |
| | | |
| | | // 创建一个新的 Dto 分页结果 |
| | |
| | | BeanUtils.copyProperties(entityPage, dtoPage); |
| | | |
| | | List<OfficialInventoryDto> dtoList = new ArrayList<>(); |
| | | |
| | | List<Long> supplierIds = entityPage.getRecords().stream() |
| | | .map(OfficialInventory::getSupplierId) |
| | | .toList(); |
| | | |
| | | Map<Long, Supply> supplyMap; |
| | | if (!supplierIds.isEmpty()) { |
| | | List<Supply> infos = supplyMapper.selectList(new LambdaQueryWrapper<Supply>().in(Supply::getId, supplierIds)); |
| | | supplyMap = infos.stream().collect(Collectors.toMap(Supply::getId, Function.identity())); |
| | | } else { |
| | | supplyMap = new HashMap<>(); |
| | | } |
| | | |
| | | |
| | | // 查询所有可用字段(CoalField) |
| | | List<CoalField> coalFields = coalFieldMapper.selectList(null); |
| | |
| | | for (OfficialInventory entity : entityPage.getRecords()) { |
| | | OfficialInventoryDto dto = new OfficialInventoryDto(); |
| | | BeanUtils.copyProperties(entity, dto); |
| | | |
| | | // 供应商信息 |
| | | Supply supply = supplyMap.get(entity.getSupplierId()); |
| | | if (supply != null) { |
| | | dto.setSupplierName(supply.getSupplierName()); |
| | | } |
| | | |
| | | List<CoalValue> coalValues; |
| | | if (entity.getMergeId() == null) { |
| | | coalValues = coalValueMapper.selectList(new LambdaQueryWrapper<CoalValue>() |
| | |
| | | public int editOfficial(OfficialInventoryDto officialInventoryDto) { |
| | | OfficialInventory officialInventory = new OfficialInventory(); |
| | | BeanUtils.copyProperties(officialInventoryDto, officialInventory); |
| | | |
| | | if (officialInventoryDto.getMergeId() != null) { |
| | | // 1. 构建查询条件 |
| | | LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getId()) |
| | | .eq(CoalValue::getType, "2"); |
| | | |
| | | // 2. 查询多个符合条件的CoalValue记录 |
| | | List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper); |
| | | |
| | | if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) { |
| | | // 3. 创建字段映射关系 (field key -> coal_value) |
| | | Map<String, String> fieldValueMap = new HashMap<>(); |
| | | for (Map<String, String> fieldMap : officialInventoryDto.getFields()) { |
| | | fieldValueMap.putAll(fieldMap); |
| | | } |
| | | |
| | | // 4. 更新 |
| | | for (CoalValue coalValue : coalValues) { |
| | | String fieldKey = coalValue.getFields(); // 数据库中的field key |
| | | if (fieldValueMap.containsKey(fieldKey)) { |
| | | String newValue = fieldValueMap.get(fieldKey); |
| | | if (!Objects.equals(coalValue.getCoalValue(), newValue)) { |
| | | coalValue.setCoalValue(newValue); |
| | | coalValueMapper.updateById(coalValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 构建查询条件 |
| | | LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getPendingId()) |
| | | .eq(CoalValue::getType, "1"); |
| | | |
| | | // 2. 查询多个符合条件的CoalValue记录 |
| | | List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper); |
| | | |
| | | if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) { |
| | | // 3. 创建字段映射关系 (field key -> coal_value) |
| | | Map<String, String> fieldValueMap = new HashMap<>(); |
| | | for (Map<String, String> fieldMap : officialInventoryDto.getFields()) { |
| | | fieldValueMap.putAll(fieldMap); |
| | | } |
| | | |
| | | // 4. 更新 |
| | | for (CoalValue coalValue : coalValues) { |
| | | String fieldKey = coalValue.getFields(); // 数据库中的field key |
| | | if (fieldValueMap.containsKey(fieldKey)) { |
| | | String newValue = fieldValueMap.get(fieldKey); |
| | | if (!Objects.equals(coalValue.getCoalValue(), newValue)) { |
| | | coalValue.setCoalValue(newValue); |
| | | coalValueMapper.updateById(coalValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return officialInventoryMapper.updateById(officialInventory); |
| | | } |
| | | |
| | |
| | | BeanUtils.copyProperties(officialInventoryDto, officialInventory); |
| | | officialInventory.setId(null); |
| | | officialInventory.setMergeId(ids.toString()); |
| | | officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserName()); |
| | | officialInventory.setSupplierId(officialInventoryDto.getSupplierId()); |
| | | officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserId()); |
| | | if (officialInventoryMapper.insert(officialInventory) <= 0) { |
| | | throw new BaseException("库存记录创建失败"); |
| | | } |