|
|
|
|
@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.modules.weixin.entity.WeChatAddress; |
|
|
|
|
import org.springblade.modules.weixin.entity.WeChatUser; |
|
|
|
|
import org.springblade.modules.weixin.mapper.WeChatAddressMapper; |
|
|
|
|
@ -34,43 +35,36 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class WeChatAddressServiceImpl extends BaseServiceImpl<WeChatAddressMapper, WeChatAddress> implements IWeChatAddressService { |
|
|
|
|
|
|
|
|
|
private final WeChatAddressMapper weChatAddressMapper; |
|
|
|
|
private final WeChatAddressMapper weChatAddressMapper; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<WeChatAddress> getPage(WeChatUser weChatUser, IPage<WeChatAddress> page) { |
|
|
|
|
return page.setRecords(weChatAddressMapper.getPage(page, weChatUser)); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public IPage<WeChatAddress> getPage(WeChatUser weChatUser, IPage<WeChatAddress> page) { |
|
|
|
|
return page.setRecords(weChatAddressMapper.getPage(page, weChatUser)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean add(WeChatAddress weChatAddress) { |
|
|
|
|
weChatAddress.setIsDefault(0); |
|
|
|
|
// if (weChatAddress.getIsDefault() == 1) {
|
|
|
|
|
// WeChatAddress address = this.getOne(Wrappers.<WeChatAddress>lambdaQuery().eq(WeChatAddress::getUserId, weChatAddress.getUserId()).eq(WeChatAddress::getIsDefault, 1));
|
|
|
|
|
// if (address != null) {
|
|
|
|
|
// address.setIsDefault(0);
|
|
|
|
|
// this.updateById(address);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
return this.save(weChatAddress); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean add(WeChatAddress weChatAddress) { |
|
|
|
|
weChatAddress.setIsDefault(0); |
|
|
|
|
return this.save(weChatAddress); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean edit(WeChatAddress weChatAddress) { |
|
|
|
|
if (weChatAddress.getIsDefault() == 1) { |
|
|
|
|
WeChatAddress address = this.getOne(Wrappers.<WeChatAddress>lambdaQuery().eq(WeChatAddress::getUserId, weChatAddress.getUserId()).eq(WeChatAddress::getIsDefault, 1)); |
|
|
|
|
if (address != null && !address.getId().equals(weChatAddress.getId())) { |
|
|
|
|
address.setIsDefault(0); |
|
|
|
|
this.updateById(address); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return this.updateById(weChatAddress); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean edit(WeChatAddress weChatAddress) { |
|
|
|
|
if (Func.isNotEmpty(weChatAddress.getIsDefault()) && weChatAddress.getIsDefault() == 1) { |
|
|
|
|
WeChatAddress address = this.getOne(Wrappers.<WeChatAddress>lambdaQuery().eq(WeChatAddress::getUserId, weChatAddress.getUserId()).eq(WeChatAddress::getIsDefault, 1)); |
|
|
|
|
if (address != null && !address.getId().equals(weChatAddress.getId())) { |
|
|
|
|
address.setIsDefault(0); |
|
|
|
|
this.updateById(address); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return this.updateById(weChatAddress); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public WeChatAddress getAddress(String phone) { |
|
|
|
|
return this.getOne(Wrappers.<WeChatAddress>lambdaQuery().eq(WeChatAddress::getPhone, phone).eq(WeChatAddress::getIsDefault, 1)); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public WeChatAddress getAddress(String phone) { |
|
|
|
|
return this.getOne(Wrappers.<WeChatAddress>lambdaQuery().eq(WeChatAddress::getPhone, phone).eq(WeChatAddress::getIsDefault, 1)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|