添加方法
public void wapAreaDatas(DiscountAreaParams params,List<DiscountArea> areaList) {
String[] areaIdArr = params.getAreaIdStr().split(",");
String[] areaNameArr = params.getAreaNameStr().split(",");
if(areaIdArr.length < 2)
throw new BusinessException("500","请选择正确的省级市关系!");
DiscountArea areaInfo = discountAreaMapper.getAreaById(Long.valueOf(areaIdArr[0]));
DiscountArea cityInfo = discountAreaMapper.getAreaById(Long.valueOf(areaIdArr[1]));
DiscountArea entity ;
if(null == areaInfo) {
for(int i = 0 ; i < areaIdArr.length ; i++) {
entity = new DiscountArea();
BeanUtils.copyProperties(params, entity);
entity.setAreaId(Long.valueOf(areaIdArr[i]));
entity.setAreaName(areaNameArr[i]);
if (i == 0) {
entity.setParentAreaId(0l);
entity.setParentAreaName("");
} else {
entity.setParentAreaId(Long.valueOf(areaIdArr[0]));
entity.setParentAreaName(areaNameArr[0]);
}
entity.setCreateTime(new Date());
areaList.add(entity);
}
}else {
entity = new DiscountArea();
if(null != cityInfo)
throw new BusinessException("500","添加的省市地区已存在,请重新选中");
BeanUtils.copyProperties(params, entity);
entity.setAreaId(Long.valueOf(areaIdArr[1]));
entity.setAreaName(areaNameArr[1]);
entity.setParentAreaId(Long.valueOf(areaIdArr[0]));
entity.setParentAreaName(areaNameArr[0]);
entity.setCreateTime(new Date());
areaList.add(entity);
}
}