BUGFIX: 获取pantone值为空时返回rgb和hsv

This commit is contained in:
2025-03-18 18:47:05 +08:00
parent 654a3829c6
commit 0500557dca
3 changed files with 93 additions and 8 deletions

View File

@@ -45,7 +45,7 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
queryWrapper.eq("pantone_index", colorLookupTable.getColorIndex());
PanTone panTone = panToneMapper.selectOne(queryWrapper);
if (Objects.isNull(panTone)) {
throw new BusinessException("pantone.not.found");
return null;
}
return coverPanToneToVo(panTone);
}
@@ -176,16 +176,19 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
@Override
public PantoneVO getPantoneByRgb(String color) {
GetRgbByHsvBatchDTO getRgbByHsvBatchDTO = new GetRgbByHsvBatchDTO();
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
int[] hsv = PantoneUtils.rgbToHsv(rgb);
if (!StringUtil.isNullOrEmpty(color)) {
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
int[] hsv = PantoneUtils.rgbToHsv(rgb);
getRgbByHsvBatchDTO.setH(hsv[0]);
getRgbByHsvBatchDTO.setS(hsv[1]);
getRgbByHsvBatchDTO.setV(hsv[2]);
}
return getByHSV(getRgbByHsvBatchDTO.getH(), getRgbByHsvBatchDTO.getS(), getRgbByHsvBatchDTO.getV());
PantoneVO pantoneVO = getByHSV(getRgbByHsvBatchDTO.getH(), getRgbByHsvBatchDTO.getS(), getRgbByHsvBatchDTO.getV());
if (Objects.isNull(pantoneVO)) {
pantoneVO = new PantoneVO(rgb[0], rgb[1], rgb[2], hsv[0], hsv[1], hsv[2]);
}
return pantoneVO;
}
@Override
@@ -215,7 +218,12 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
QueryWrapper<PanTone> queryWrapper = new QueryWrapper<>();
queryWrapper.in("pantone_index", colorLookupTables.stream()
.map(ColorLookupTable::getColorIndex).collect(Collectors.toList()));
return coverPanToneToVoList(panToneMapper.selectList(queryWrapper), IndexToValue, valueToHsv, hsvBatch);
List<PantoneVO> pantoneVOS = coverPanToneToVoList(panToneMapper.selectList(queryWrapper), IndexToValue, valueToHsv, hsvBatch);
if (pantoneVOS.isEmpty() && hsvBatch.size() == 1){
int[] rgb = PantoneUtils.hsvToRgb(hsvBatch.get(0).getH(), hsvBatch.get(0).getS(), hsvBatch.get(0).getV());
pantoneVOS.add(new PantoneVO(rgb[0], rgb[1], rgb[2], hsvBatch.get(0).getH(), hsvBatch.get(0).getS(), hsvBatch.get(0).getV()));
}
return pantoneVOS;
}
private PantoneVO coverPanToneToVo(PanTone panTone) {
@@ -234,7 +242,8 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
, Map<Integer, Integer> indexToValue, Map<Integer, GetRgbByHsvBatchDTO> valueToHsv,
List<GetRgbByHsvBatchDTO> hsvBatch) {
if (CollectionUtil.isEmpty(panTones)) {
throw new BusinessException("panTones.not.found", ResultEnum.PROMPT.getCode());
return Lists.newArrayList();
// throw new BusinessException("panTones.not.found", ResultEnum.PROMPT.getCode());
}
List<PantoneVO> templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> {
d.setId(o.getPantoneIndex());