总共四种情况:
// 1. top->bottom 最大listSort+1给top 其余所有的listSort-1
if (EquityEnum.TOP_TO_BOTTOM.getValue().equals(dto.getAdjustFlag())) {
adjustEquity(dto, maxSort);
return equityItemInfoPOExtMapper.adjustTopToBottom(dto);
}
// 2. bottom->top bottom的listSort变0 其余所有的listSort+1
if (EquityEnum.BOTTOM_TO_TOP.getValue().equals(dto.getAdjustFlag())) {
adjustEquity(dto, 0);
return equityItemInfoPOExtMapper.adjustBottomToTop(dto);
}
// 3. high->low low的给high,high的給low
if (EquityEnum.HIGH_TO_LOW.getValue().equals(dto.getAdjustFlag())) {
EquityItemInfoPO highPO = equityItemInfoPOMapper.selectByPrimaryKey(dto.getItemId());
Integer highSort = highPO.getListSort();
EquityItemInfoPO lowPO = equityItemInfoPOExtMapper.selectNextRecord(dto);
Integer lowSort = lowPO.getListSort();
lowPO.setListSort(highSort);
highPO.setListSort(lowSort);
int i = equityItemInfoPOMapper.updateByPrimaryKey(highPO);
int j = equityItemInfoPOMapper.updateByPrimaryKey(lowPO);
if (i > 0 && j > 0) {
return true;
}
return false;
}
// 4. low->high high的给low,low的給high
if (EquityEnum.LOW_TO_HIGH.getValue().equals(dto.getAdjustFlag())) {
EquityItemInfoPO lowPO = equityItemInfoPOMapper.selectByPrimaryKey(dto.getItemId());
Integer lowSort = lowPO.getListSort();
EquityItemInfoPO highPO = equityItemInfoPOExtMapper.selectBeforeRecord(dto);
Integer highSort = highPO.getListSort();
lowPO.setListSort(highSort);
highPO.setListSort(lowSort);
int i = equityItemInfoPOMapper.updateByPrimaryKey(highPO);
int j = equityItemInfoPOMapper.updateByPrimaryKey(lowPO);
if (i > 0 && j > 0) {
return true;
}
return false;
}