use of cn.exrick.manager.pojo.TbAddress in project xmall by Exrick.
the class AddressServiceImpl method setOneDefault.
public void setOneDefault(TbAddress tbAddress) {
// 设置唯一默认
if (tbAddress.getIsDefault()) {
TbAddressExample example = new TbAddressExample();
TbAddressExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(tbAddress.getUserId());
List<TbAddress> list = tbAddressMapper.selectByExample(example);
for (TbAddress tbAddress1 : list) {
tbAddress1.setIsDefault(false);
tbAddressMapper.updateByPrimaryKey(tbAddress1);
}
}
}
use of cn.exrick.manager.pojo.TbAddress in project xmall by Exrick.
the class AddressServiceImpl method getAddressList.
@Override
public List<TbAddress> getAddressList(Long userId) {
List<TbAddress> list = new ArrayList<>();
TbAddressExample example = new TbAddressExample();
TbAddressExample.Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
list = tbAddressMapper.selectByExample(example);
if (list == null) {
throw new XmallException("获取默认地址列表失败");
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getIsDefault()) {
Collections.swap(list, 0, i);
break;
}
}
return list;
}
Aggregations