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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations