Procházet zdrojové kódy

处理只有一条地址不设为默认地址的情况

hulh před 8 roky
rodič
revize
5274c9e64e

+ 6 - 15
src/main/java/com/uas/platform/b2c/logistics/service/impl/AddressServiceImpl.java

@@ -37,7 +37,6 @@ public class AddressServiceImpl implements AddressService {
 	public void delete(Long addid) {
 		if (addressDao.exists(addid)) {
 			Address address = addressDao.findOne(addid);
-			int modifyNum = address.getNum();
 			List<Address> addresses = null;
 			addressDao.delete(addid);
 			int type = address.getType();
@@ -52,12 +51,9 @@ public class AddressServiceImpl implements AddressService {
 					Address add = addresses.get(0);
 					add.setNum(1);
 				}else {
-					int num = 0;
-					if (modifyNum == 1) {
-						num = 1;
-					}
+					int num = addresses.get(0).getNum();
 					for (Address add : addresses){
-						add.setNum(++num);
+						add.setNum(num++);
 					}
 				}
 			}
@@ -76,7 +72,6 @@ public class AddressServiceImpl implements AddressService {
 	@Override
 	public void setTop(Long addid, boolean setTop) {
 		Address address = addressDao.findOne(addid); //查询操作的Address
-//		System.out.println("setTop=" + setTop);
 		Long useruu = address.getUseruu();
 		int type = address.getType();
 		List<Address> addresses = null;
@@ -89,7 +84,6 @@ public class AddressServiceImpl implements AddressService {
 		long modifyId = address.getId().longValue();
 		int modifyNum = address.getNum().intValue();
 		if (setTop){
-//			System.out.println("设为默认地址情况");
 			for (Address add : addresses) {
 				if (add.getId().longValue() == modifyId) {
 					add.setNum(1);
@@ -100,14 +94,12 @@ public class AddressServiceImpl implements AddressService {
 			}
 		}else {
 			if (modifyNum == 1){ //取消默认地址
-//				System.out.println("取消默认地址情况");
 				for (Address add : addresses) { //空出默认地址位置
 					add.setNum(++num);
 				}
 			}else {
 				int firstNum = addresses.get(0).getNum();
 				if (firstNum == 1){ //有默认地址情况
-//					System.out.println("有默认地址新增地址情况");
 					num++; //空出默认地址位置
 					for (Address add : addresses) {
 						if (add.getNum() != 1){
@@ -120,7 +112,6 @@ public class AddressServiceImpl implements AddressService {
 						}
 					}
 				}else { //没有默认地址情况
-//					System.out.println("没有默认地址新增地址情况");
 					num++; //空出默认地址位置
 					for (Address add : addresses) {
 						if (add.getId().longValue() != modifyId){
@@ -165,13 +156,13 @@ public class AddressServiceImpl implements AddressService {
 		}
 		Long modifyId = address.getId();
 		Address add = save(address);
-		System.out.println(address.getId());
+		if (modifyId == null && add.getNum().intValue() == 1){
+			isSetTop = true;
+		}
 		if(modifyId == null || isSetTop) { //只有新增加的地址 或者需要被置顶的地址 才需要重新排序。
-//			System.out.println("新增地址或设为默认地址");
 			setTop(add.getId(), isSetTop);
 		}
-		if (address.getNum() == 1 && !isSetTop) { //取消默认地址的时候需要重新排序
-//			System.out.println("取消默认地址");
+		if (address.getNum().intValue() == 1 && !isSetTop) { //取消默认地址的时候需要重新排序
 			setTop(add.getId(), isSetTop);
 		}
 		return add;