方法一 :保存校验,根据业务类型和税率判断哪些记录重复(不推荐)
import org.apache.commons.collections.CollectionUtils;
private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {
bvolist = translateBodyVO(bvolist);
JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);
if(bvos != null && bvos.length > 0){
Map<String, List<UFDouble>> map = new HashMap<String, List<UFDouble>>();
for(int i = 0; i < bvos.length; i++){
String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());
UFDouble taxrate = NullValueUtils.getNullUFdoubleValue((bvos[i].getTaxrate()));
if(map.containsKey(ywlx)){
List<UFDouble> list = map.get(ywlx);
list.add(taxrate);
map.put(ywlx, list);
}else{
List<UFDouble> list = new ArrayList<>();
list.add(taxrate);
map.put(ywlx, list);
}
}
StringBuilder sb = new StringBuilder();
for(String ywlx : map.keySet()){
if(map.containsKey(ywlx)){
List<UFDouble> list = map.get(ywlx);
Set<UFDouble> set = new HashSet<>(list);
Collection<UFDouble> rs = CollectionUtils.disjunction(list, set);
List<UFDouble> newList = new ArrayList<>(rs);
if(newList!=null && newList.size()>0){
sb.append("业务类型为:");
sb.append(ywlx);
sb.append(",税率为:");
for (UFDouble str : newList) {
sb.append(str).append(",");
}
sb.delete(sb.length() - 1, sb.length());
sb.append(";");
}
}
}
if(sb!=null&&sb.length()>0){
throw new BusinessException(sb+ "表体重复,请检查!");
}
}
}
private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {
SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {
"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"
});
return bvolist;
}
方法二 :保存校验,根据业务类型和税率判断哪些记录重复(推荐)
private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {
bvolist = translateBodyVO(bvolist);
JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);
if(bvos != null && bvos.length > 0){
List<String> ywlxList = new ArrayList<String>();
List<UFDouble> taxrateList = new ArrayList<UFDouble>();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < bvos.length; i++){
String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());
UFDouble taxrate = NullValueUtils.getNullUFdoubleValue((bvos[i].getTaxrate()));
String rowno = NullValueUtils.getNullStringValue(bvos[i].getRowno().substring(0, bvos[i].getRowno().length()-1));
String classify = NullValueUtils.getNullStringValue(bvos[i].getClassify());
if(ywlxList.contains(ywlx) && taxrateList.contains(taxrate)){
sb.append("行号为:").append(rowno);
sb.append(",业务类型为:").append(ywlx);
sb.append(",分类为:").append(classify);
sb.append(",税率为:").append(taxrate);
sb.append(";");
}
ywlxList.add(ywlx);
taxrateList.add(taxrate);
}
if(sb != null && sb.length() > 0){
throw new BusinessException(sb+ "表体重复,请检查!");
}
}
}
private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {
SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {
"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"
});
return bvolist;
}
方法三 :保存校验,根据业务类型和税率判断哪些记录重复(极力推荐)
private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {
bvolist = translateBodyVO(bvolist);
JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);
if(bvos != null && bvos.length > 0){
Map<String, Map<String,List<String>> >map = new HashMap<String, Map<String,List<String>>>();
for(int i = 0; i < bvos.length; i++){
if(bvos[i].getYwlx() != null && !bvos[i].getYwlx().equals("")
&&bvos[i].getTaxrate() != null){
String rowno = NullValueUtils.getNullStringValue(i+1);
String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());
String classify = NullValueUtils.getNullStringValue(bvos[i].getClassify());
UFDouble taxrate = NullValueUtils.getNullUFdoubleValue(bvos[i].getTaxrate()).setScale(2, UFDouble.ROUND_HALF_UP);
if(map.containsKey(ywlx+"@"+taxrate)){
Map<String, List<String>> classifymap = map.get(ywlx+"@"+taxrate);
List<String> list = classifymap.get(classify);
list.add(rowno);
classifymap.put(classify, list);
map.put(ywlx+"@"+taxrate, classifymap);
}else{
Map<String, List<String>> classifymap = new HashMap<String,List<String>>();
List<String> list = new ArrayList<>();
list.add(rowno);
classifymap.put(classify, list);
map.put(ywlx+"@"+taxrate, classifymap);
}
}
}
StringBuilder sb = new StringBuilder();
for (String ywlxTaxrate : map.keySet()) {
Map<String, List<String>> classifymap = map.get(ywlxTaxrate);
for(String classify : classifymap.keySet()){
List<String> list = classifymap.get(classify);
if(list != null && list.size() > 1){
Collections.sort(list);
for (String str : list) {
sb.append("第").append(str).append("行").append("和");
}
sb.delete(sb.length() - 1, sb.length());
sb.append("的分类:").append(classify);
int index = ywlxTaxrate.indexOf("@");
sb.append(",业务类型:").append(ywlxTaxrate.substring(0,index));
sb.append(",税率:").append(ywlxTaxrate.substring(index+1,ywlxTaxrate.length()));
sb.append("重复;");
}
}
}
if(sb != null && sb.length() > 0){
sb.delete(sb.length() - 3, sb.length());
throw new BusinessException(sb+"重复,不允许保存,请检查!");
}
}
}
private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {
SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {
"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"
});
return bvolist;
}