乐高项目分析
2017-11-13 本文已影响131人
wanggs
取消订单
首先根据订单id找到订单,第一判断是否有该订单,或者订单与本人对不上号,根据订单获取订单槽位置编码,重新入库,然后更新订单状态
取消订单api
/**
* 取消订单
* @param param
* @return
* @author tanghc
*/
@RequestMapping(value="cancelOrder.do",method=RequestMethod.POST)
public Ret cancelOrder(@RequestBody OrderParam param) {
User user = UserContext.getLoginUser();
long orderId = param.getOrderId();
orderService.cancelOrder(user, orderId);
return Rets.success();
}
/**
* 取消订单
* @param user
* @param orderId
* @author tanghc
*/
@Transactional
public void cancelOrder(User user,long orderId) {
Orders order = ordersDao.get(orderId);
if(order == null) {
throw new CommonException(MsgTypes.NULL_OBJECT);
}
if(!user.getId().equals(order.getUserId())) {
throw new CommonException(MsgTypes.ERROR_OPT);
}
String goodsCode = order.getGoodsCode();
// 重新入库
this.putGoodsBoxInStore(goodsCode);
// 修改订单状态
order.setStatus(OrdersState.State.cancel.getStatus());
order.setUpdateTime(new Date());
// 跟新
ordersDao.updateNotNull(order);
}
// 重新入库
private void putGoodsBoxInStore(String goodsCode) {
GoodsPosition goodsPos = goodsPositionDao.getByProperty("goodsCode", goodsCode);
goodsPos.setState(GoodsState.State.inStore.getState());
goodsPositionDao.updateNotNull(goodsPos);
}
修改收货地址
业务逻辑: 根据订单号找到该订单,判断该用户是否有本订单,如果有,根据用户根号的地址id,获取地址详情,然后设置到订单中,最后跟新订单
/**
* 更新地址
* @param orderParam
* @return
* @author tanghc
*/
@RequestMapping(value="updateOrderUserInfo.do",method=RequestMethod.POST)
public Ret updateOrderUserInfo(@RequestBody OrderParam orderParam) {
Orders orders = ordersDao.get(orderParam.getOrderId());
// 检查订单
Checks.checkOrder(orders);
orderService.updateOrderUserInfo(orders.getId(),orderParam.getAddressId());
return Rets.success();
}
检查订单
package app.front;
import app.base.entity.legouser.Orders;
import app.base.entity.legouser.User;
import app.base.utils.CheckUtils;
/**
* @author tanghc
*
*/
public class Checks {
/**
* 检查订单
* @param orders
* @param user
* @author tanghc
*/
public static void checkOrder(Orders orders) {
User user = UserContext.getLoginUser();
CheckUtils.checkOrder(orders, user);
}
}
检查订单公交类
package app.base.utils;
import app.base.entity.legouser.Orders;
import app.base.entity.legouser.User;
import component.common.exception.CommonException;
import component.common.msg.MsgTypes;
/**
* @author tanghc
*
*/
public class CheckUtils {
/**
* 检查订单
* @param orders
* @param user
* @author tanghc
*/
public static void checkOrder(Orders orders,User user) {
if(orders == null || user == null) {
throw new NullPointerException();
}
if(!orders.getUserId().equals(user.getId())) {
throw new CommonException(MsgTypes.ERROR_OPT);
}
}
}
更新订单
/**
* 更新订单地址信息
* @param orderId
* @author tanghc
*/
public void updateOrderUserInfo(long orderId,long addressId) {
Orders orders = ordersDao.get(orderId);
UserAddress userAddress = userAddressDao.get(addressId);
if(userAddress != null) {
orders.setMobile(userAddress.getPhone());
orders.setAddress(UserAddressService.buildAddressInfo(userAddress));
orders.setRealName(userAddress.getRealname());
ordersDao.updateNotNull(orders);
}
}