Search in sources :

Example 1 with TbAddressExample

use of cn.exrick.manager.pojo.TbAddressExample 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);
        }
    }
}
Also used : TbAddress(cn.exrick.manager.pojo.TbAddress) TbAddressExample(cn.exrick.manager.pojo.TbAddressExample)

Example 2 with TbAddressExample

use of cn.exrick.manager.pojo.TbAddressExample 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;
}
Also used : TbAddress(cn.exrick.manager.pojo.TbAddress) TbAddressExample(cn.exrick.manager.pojo.TbAddressExample) ArrayList(java.util.ArrayList) XmallException(cn.exrick.common.exception.XmallException)

Aggregations

TbAddress (cn.exrick.manager.pojo.TbAddress)2 TbAddressExample (cn.exrick.manager.pojo.TbAddressExample)2 XmallException (cn.exrick.common.exception.XmallException)1 ArrayList (java.util.ArrayList)1