|
@@ -62,6 +62,31 @@ public class CargoOwnerAddressInfoServiceImpl extends ServiceImpl<CargoOwnerAddr
|
|
|
*/
|
|
|
@Override
|
|
|
public String addCargoOwnerAddress(HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo){
|
|
|
+ //查询货主有没有置顶地址
|
|
|
+ List<HyCargoOwnerAddressInfo> hyCargoOwnerAddressInfoList = this.selectList(new EntityWrapper<HyCargoOwnerAddressInfo>()
|
|
|
+ .eq("common_id",hyCargoOwnerAddressInfo.getCommonId()).eq("delete_flag","0")
|
|
|
+ .eq("topping_flag","1").orderBy("sort",true));
|
|
|
+ //没有置顶地址的时候,新增的地址序号最大
|
|
|
+ if (CollectionUtils.isEmpty(hyCargoOwnerAddressInfoList)){
|
|
|
+ //查询货主所有地址,倒序
|
|
|
+ List<HyCargoOwnerAddressInfo> hyCargoOwnerAddressInfoList1 = this.selectList(new EntityWrapper<HyCargoOwnerAddressInfo>()
|
|
|
+ .eq("common_id",hyCargoOwnerAddressInfo.getCommonId()).eq("delete_flag","0").orderBy("sort",false));
|
|
|
+ if (hyCargoOwnerAddressInfoList1.size()==0){
|
|
|
+ //第一个地址
|
|
|
+ hyCargoOwnerAddressInfo.setSort(1);
|
|
|
+ }else {
|
|
|
+ hyCargoOwnerAddressInfo.setSort(hyCargoOwnerAddressInfoList1.get(0).getSort()+1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //有置顶地址
|
|
|
+ else {
|
|
|
+ hyCargoOwnerAddressInfo.setSort(hyCargoOwnerAddressInfoList.get(0).getSort());
|
|
|
+ for (int i=0;i<hyCargoOwnerAddressInfoList.size();i++){
|
|
|
+ int t = hyCargoOwnerAddressInfoList.get(i).getSort();
|
|
|
+ hyCargoOwnerAddressInfoList.get(i).setSort(t+1);
|
|
|
+ }
|
|
|
+ this.updateBatchById(hyCargoOwnerAddressInfoList);
|
|
|
+ }
|
|
|
//新增主键id
|
|
|
hyCargoOwnerAddressInfo.setId(IdGenerator.generateUUID());
|
|
|
this.insert(hyCargoOwnerAddressInfo);
|
|
@@ -86,6 +111,21 @@ public class CargoOwnerAddressInfoServiceImpl extends ServiceImpl<CargoOwnerAddr
|
|
|
@Override
|
|
|
public void deleteCargoOwnerAddress(String id) {
|
|
|
HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo = this.selectById(id);
|
|
|
+ //查询货主所有地址,倒序
|
|
|
+ List<HyCargoOwnerAddressInfo> hyCargoOwnerAddressInfoList = this.selectList(new EntityWrapper<HyCargoOwnerAddressInfo>()
|
|
|
+ .eq("common_id",hyCargoOwnerAddressInfo.getCommonId()).eq("delete_flag","0")
|
|
|
+ .orderBy("sort",false));
|
|
|
+ //要删除的地址不是序号最大的
|
|
|
+ if (hyCargoOwnerAddressInfo.getId() != hyCargoOwnerAddressInfoList.get(0).getId()){
|
|
|
+ for (HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo1 : hyCargoOwnerAddressInfoList){
|
|
|
+ //该地址比要删除的地址序号大,序号-1
|
|
|
+ if (hyCargoOwnerAddressInfo1.getSort() > hyCargoOwnerAddressInfo.getSort()){
|
|
|
+ int t = hyCargoOwnerAddressInfo1.getSort();
|
|
|
+ hyCargoOwnerAddressInfo1.setSort(t-1);
|
|
|
+ this.updateById(hyCargoOwnerAddressInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
this.deleteById(hyCargoOwnerAddressInfo.getId());
|
|
|
}
|
|
|
|
|
@@ -96,10 +136,10 @@ public class CargoOwnerAddressInfoServiceImpl extends ServiceImpl<CargoOwnerAddr
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String setDefault(HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo) {
|
|
|
- //查询货主所有地址
|
|
|
+ //查询货主所有地址,倒序
|
|
|
List<HyCargoOwnerAddressInfo> hyCargoOwnerAddressInfoList = this.selectList(new EntityWrapper<HyCargoOwnerAddressInfo>()
|
|
|
.eq(HyCargoOwnerAddressInfo.QueryFiles.COMMON_ID, hyCargoOwnerAddressInfo.getCommonId())
|
|
|
- .eq(HyCargoOwnerAddressInfo.QueryFiles.DELETE_FLAG, NumberConstant.CONSTANT0));
|
|
|
+ .eq(HyCargoOwnerAddressInfo.QueryFiles.DELETE_FLAG, NumberConstant.CONSTANT0).orderBy("sort",false));
|
|
|
if(!CollectionUtils.isEmpty(hyCargoOwnerAddressInfoList)){
|
|
|
for (HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo1 : hyCargoOwnerAddressInfoList){
|
|
|
//id相等设置默认,其余数据取消默认
|
|
@@ -115,6 +155,21 @@ public class CargoOwnerAddressInfoServiceImpl extends ServiceImpl<CargoOwnerAddr
|
|
|
}else {
|
|
|
//设置置顶
|
|
|
hyCargoOwnerAddressInfo1.setToppingFlag("1");
|
|
|
+ //货主不止一条地址的时候
|
|
|
+ if (hyCargoOwnerAddressInfoList.size() != 1){
|
|
|
+ //要置顶的地址不是序号最大的
|
|
|
+ if (hyCargoOwnerAddressInfo1.getId() != hyCargoOwnerAddressInfoList.get(0).getId()){
|
|
|
+ for (HyCargoOwnerAddressInfo hyCargoOwnerAddressInfo2 : hyCargoOwnerAddressInfoList){
|
|
|
+ //比此地址序号大的-1
|
|
|
+ if (hyCargoOwnerAddressInfo2.getSort() > hyCargoOwnerAddressInfo1.getSort()){
|
|
|
+ int t = hyCargoOwnerAddressInfo2.getSort();
|
|
|
+ hyCargoOwnerAddressInfo2.setSort(t-1);
|
|
|
+ this.updateById(hyCargoOwnerAddressInfo2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hyCargoOwnerAddressInfo1.setSort(hyCargoOwnerAddressInfoList.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
this.updateById(hyCargoOwnerAddressInfo1);
|
|
|
}else {
|