培训day10(新增保存校验还款编号字段不能重复)
1.业务需求:
2.代码实现
InsertBeforeRule.java
/*新增保存时,校验还款编号字段不能重复,如果重复,提示哪行和哪行重复*/
private void saveCheckRepeatHkno(AggYhlypxhtfkdVO aggvo) throws BusinessException{
YhlypxhtfkBVO[] bvos = (YhlypxhtfkBVO[]) aggvo.getChildren(YhlypxhtfkBVO.class);
if(bvos != null && bvos.length > 0){
Map<String, List<String>> map = new HashMap<String, List<String>>();
//往map中存值,往list中存值
for(int i = 0; i < bvos.length; i++){
if(bvos[i].getHkno() != null && !bvos[i].getHkno().equals("")){
String rowno = bvos[i].getRowno();
String hkno = bvos[i].getHkno();
if(map.containsKey(hkno)){
List<String> list = map.get(hkno);
list.add(rowno);
}else{
List<String> list = new ArrayList<>();
list.add(rowno);
map.put(hkno, list);
}
}
}
//遍历map,遍历list
StringBuilder sb = new StringBuilder();
for (String hkno : map.keySet()) {
List<String> list = map.get(hkno);
if(list != null && list.size() > 1){
Collections.sort(list);//对list进行升序排序
for (String str : list) {
sb.append(str).append(",");
}
sb.delete(sb.length() - 1, sb.length());
sb.append(";");
}
}
if(sb != null && sb.length() > 0){
throw new BusinessException(sb + "行号还款编号对应值重复;");
}
}
}
2.代码实现
InvoiceAction.java
/*点击开票按钮时,表体数量和数量(开票)必须相同,如果不相同,提示哪些行不相同*/
private void CheakSlSlkp(SaleInvoiceBVO[] bvos) throws BusinessException {
if(bvos != null && bvos.length > 0){
List<String> list = new ArrayList<>();
for(int i = 0; i < bvos.length; i++){
//依次获取各行行号
String rowno = bvos[i].getCrowno();
//依次获取各行数量
UFDouble num = NullValueUtils.getNullUFdoubleValue(bvos[i].getNastnum());
//数量(开票)
UFDouble numkp = NullValueUtils.getNullUFdoubleValue(bvos[i].getVbdef5());
//如果表体数量和数量开票不相等时,将主键和对应行号的List集合存入map
if(num.sub(numkp).compareTo(UFDouble.ZERO_DBL) != 0){
list.add(rowno);
}
}
if(list != null && list.size() > 1){
Collections.sort(list);//对list进行升序排序
StringBuilder sb = new StringBuilder();
for(String rowno : list){
sb.append(rowno).append(",");
}
sb.delete(sb.length()-1, sb.length());;
throw new BusinessException("第" + sb.toString() + "行的数量和数量(开票)不相等,请检查!");
}
}
}