Search in sources :

Example 16 with XmallException

use of cn.exrick.common.exception.XmallException 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)

Example 17 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class MemberServiceImpl method imageUpload.

@Override
public String imageUpload(Long userId, String token, String imgData) {
    // 过滤data:URL
    String base64 = QiniuUtil.base64Data(imgData);
    String imgPath = QiniuUtil.qiniuBase64Upload(base64);
    TbMember tbMember = tbMemberMapper.selectByPrimaryKey(userId);
    if (tbMember == null) {
        throw new XmallException("通过id获取用户失败");
    }
    tbMember.setFile(imgPath);
    if (tbMemberMapper.updateByPrimaryKey(tbMember) != 1) {
        throw new XmallException("更新用户头像失败");
    }
    // 更新缓存
    Member member = loginService.getUserByToken(token);
    member.setFile(imgPath);
    jedisClient.set("SESSION:" + token, new Gson().toJson(member));
    return imgPath;
}
Also used : TbMember(cn.exrick.manager.pojo.TbMember) Gson(com.google.gson.Gson) XmallException(cn.exrick.common.exception.XmallException) TbMember(cn.exrick.manager.pojo.TbMember) Member(cn.exrick.manager.dto.front.Member)

Example 18 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class OrderServiceImpl method getOrder.

@Override
public Order getOrder(Long orderId) {
    Order order = new Order();
    TbOrder tbOrder = tbOrderMapper.selectByPrimaryKey(String.valueOf(orderId));
    if (tbOrder == null) {
        throw new XmallException("通过id获取订单失败");
    }
    String validTime = judgeOrder(tbOrder);
    if (validTime != null) {
        order.setFinishDate(validTime);
    }
    // orderId
    order.setOrderId(Long.valueOf(tbOrder.getOrderId()));
    // orderStatus
    order.setOrderStatus(String.valueOf(tbOrder.getStatus()));
    // createDate
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    String createDate = formatter.format(tbOrder.getCreateTime());
    order.setCreateDate(createDate);
    // closeDate
    if (tbOrder.getCloseTime() != null) {
        String closeDate = formatter.format(tbOrder.getCloseTime());
        order.setCloseDate(closeDate);
    }
    // finishDate
    if (tbOrder.getEndTime() != null && tbOrder.getStatus() == 4) {
        String finishDate = formatter.format(tbOrder.getEndTime());
        order.setFinishDate(finishDate);
    }
    // address
    TbOrderShipping tbOrderShipping = tbOrderShippingMapper.selectByPrimaryKey(tbOrder.getOrderId());
    TbAddress address = new TbAddress();
    address.setUserName(tbOrderShipping.getReceiverName());
    address.setStreetName(tbOrderShipping.getReceiverAddress());
    address.setTel(tbOrderShipping.getReceiverPhone());
    order.setAddressInfo(address);
    // orderTotal
    if (tbOrder.getPayment() == null) {
        order.setOrderTotal(new BigDecimal(0));
    } else {
        order.setOrderTotal(tbOrder.getPayment());
    }
    // goodsList
    TbOrderItemExample exampleItem = new TbOrderItemExample();
    TbOrderItemExample.Criteria criteriaItem = exampleItem.createCriteria();
    criteriaItem.andOrderIdEqualTo(tbOrder.getOrderId());
    List<TbOrderItem> listItem = tbOrderItemMapper.selectByExample(exampleItem);
    List<CartProduct> listProduct = new ArrayList<>();
    for (TbOrderItem tbOrderItem : listItem) {
        CartProduct cartProduct = DtoUtil.TbOrderItem2CartProduct(tbOrderItem);
        listProduct.add(cartProduct);
    }
    order.setGoodsList(listProduct);
    return order;
}
Also used : Order(cn.exrick.manager.dto.front.Order) PageOrder(cn.exrick.manager.dto.front.PageOrder) ArrayList(java.util.ArrayList) XmallException(cn.exrick.common.exception.XmallException) BigDecimal(java.math.BigDecimal) CartProduct(cn.exrick.manager.dto.front.CartProduct) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class OrderServiceImpl method judgeOrder.

/**
 * 判断订单是否超时未支付
 */
public String judgeOrder(TbOrder tbOrder) {
    String result = null;
    if (tbOrder.getStatus() == 0) {
        // 判断是否已超1天
        long diff = System.currentTimeMillis() - tbOrder.getCreateTime().getTime();
        long days = diff / (1000 * 60 * 60 * 24);
        if (days >= 1) {
            // 设置失效
            tbOrder.setStatus(5);
            tbOrder.setCloseTime(new Date());
            if (tbOrderMapper.updateByPrimaryKey(tbOrder) != 1) {
                throw new XmallException("更新订单失效失败");
            }
        } else {
            // 返回到期时间
            long time = tbOrder.getCreateTime().getTime() + 1000 * 60 * 60 * 24;
            result = String.valueOf(time);
        }
    }
    return result;
}
Also used : XmallException(cn.exrick.common.exception.XmallException) Date(java.util.Date)

Example 20 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class OrderServiceImpl method cancelOrder.

@Override
public int cancelOrder(Long orderId) {
    TbOrder tbOrder = tbOrderMapper.selectByPrimaryKey(String.valueOf(orderId));
    if (tbOrder == null) {
        throw new XmallException("通过id获取订单失败");
    }
    tbOrder.setStatus(5);
    tbOrder.setCloseTime(new Date());
    if (tbOrderMapper.updateByPrimaryKey(tbOrder) != 1) {
        throw new XmallException("取消订单失败");
    }
    return 1;
}
Also used : XmallException(cn.exrick.common.exception.XmallException) Date(java.util.Date)

Aggregations

XmallException (cn.exrick.common.exception.XmallException)47 Date (java.util.Date)22 TbMember (cn.exrick.manager.pojo.TbMember)12 DataTablesResult (cn.exrick.common.pojo.DataTablesResult)11 TbMemberExample (cn.exrick.manager.pojo.TbMemberExample)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Gson (com.google.gson.Gson)4 TbItem (cn.exrick.manager.pojo.TbItem)3 TbThanksExample (cn.exrick.manager.pojo.TbThanksExample)3 PageInfo (com.github.pagehelper.PageInfo)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 CartProduct (cn.exrick.manager.dto.front.CartProduct)2 SearchItem (cn.exrick.manager.dto.front.SearchItem)2 TbContentCategory (cn.exrick.manager.pojo.TbContentCategory)2 TbItemCat (cn.exrick.manager.pojo.TbItemCat)2 TbItemDesc (cn.exrick.manager.pojo.TbItemDesc)2 TbThanks (cn.exrick.manager.pojo.TbThanks)2 TransportClient (org.elasticsearch.client.transport.TransportClient)2 Settings (org.elasticsearch.common.settings.Settings)2