Commit f45e0f2a by weijiguang

下单时校验订单中sku数量

parent ff201708
package com.soss.web.controller.coffee;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.soss.common.annotation.Log;
import com.soss.common.constant.HttpStatus;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.common.exception.ServiceException;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Order;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.service.impl.CustomerServiceImpl;
import com.soss.system.service.impl.OrderServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soss.common.annotation.Log;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.enums.BusinessType;
import com.soss.system.domain.Order;
import com.soss.system.service.IOrderService;
import com.soss.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* 订单Controller
*
*
* @author zxq
* @date 2022-04-28
*/
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController
{
public class OrderController extends BaseController {
@Autowired
private OrderServiceImpl orderService;
@Autowired
......@@ -51,8 +42,7 @@ public class OrderController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:order:list')")
@GetMapping("/list")
public TableDataInfo list(OrderQuery orderQuery)
{
public TableDataInfo list(OrderQuery orderQuery) {
startPage();
List<Order> list = orderService.selectOrderList(orderQuery);
return getDataTable(list);
......@@ -63,15 +53,13 @@ public class OrderController extends BaseController
* 获取订单详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
{
public AjaxResult getInfo(@PathVariable("id") String id) {
return AjaxResult.success(orderService.selectOrderById(id));
}
@PostMapping("/check")
public AjaxResult check(@RequestBody Order order)
{
public AjaxResult check(@RequestBody Order order) {
return orderService.check(order);
}
......@@ -80,34 +68,34 @@ public class OrderController extends BaseController
*/
@Log(title = "订单", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(HttpServletRequest request, @RequestBody Order order)
{
public AjaxResult add(HttpServletRequest request, @RequestBody Order order) {
LoginUser loginUser = tokenService.getLoginUser(request);
AjaxResult ajaxResult = orderService.insertOrder(loginUser,order);
if(HttpStatus.SUCCESS != (int)ajaxResult.get(AjaxResult.CODE_TAG)){
return ajaxResult;
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order);
if (HttpStatus.SUCCESS != (int) ajaxResult.get(AjaxResult.CODE_TAG)) {
return ajaxResult;
}
int amount = order.getAmount().movePointRight(2).intValue();
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if(payInfo !=null){
payInfo.put("orderId",order.getId());
if (payInfo != null) {
payInfo.put("orderId", order.getId());
return AjaxResult.success(payInfo);
}else{
} else {
throw new ServiceException("微信支付发生异常");
}
}
@RequestMapping("/payOrder")
public AjaxResult cancel(HttpServletRequest request, String orderId)
{
public AjaxResult cancel(HttpServletRequest request, String orderId) {
Order order = orderService.selectOrderById(orderId);
order.setOrderNo(orderService.getOrderNo(order.getSource()));
orderService.updateOrder(order);
int amount = order.getAmount().movePointRight(2).intValue();
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if(payInfo !=null){
if (payInfo != null) {
return AjaxResult.success(payInfo);
}else{
} else {
throw new ServiceException("微信支付发生异常");
}
}
......@@ -119,13 +107,12 @@ public class OrderController extends BaseController
@PreAuthorize("@ss.hasPermi('system:order:edit')")
@Log(title = "订单", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Order order)
{
public AjaxResult edit(@RequestBody Order order) {
return toAjax(orderService.updateOrder(order));
}
@RequestMapping("/cancel")
public AjaxResult cancel(String orderId)
{
public AjaxResult cancel(String orderId) {
return toAjax(orderService.cancel(orderId));
}
......
......@@ -4,6 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -26,6 +28,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
* @author zxq
*/
@Component
@Slf4j
public class TokenService
{
// 令牌自定义标识
......@@ -71,6 +74,7 @@ public class TokenService
}
catch (Exception e)
{
log.error("", e);
}
}
return null;
......
package com.soss.system.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.constant.HttpStatus;
......@@ -16,34 +10,36 @@ import com.soss.common.utils.StringUtils;
import com.soss.common.utils.spring.SpringUtils;
import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.domain.vo.orderTaking.CategoryVo;
import com.soss.system.domain.vo.orderTaking.GoodsVo;
import com.soss.system.domain.vo.orderTaking.OrderTakingVo;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.service.IOrderService;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.mapper.*;
import com.soss.system.service.IOrderService;
import com.soss.system.utils.SendSmsUtil;
import com.soss.system.weixin.util.SendMessageUtils;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.security.core.token.TokenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 订单Service业务层处理
*
*
* @author zxq
* @date 2022-04-28
*/
@Service
public class OrderServiceImpl implements IOrderService
{
public class OrderServiceImpl implements IOrderService {
@Autowired
private OrderMapper orderMapper;
@Autowired
......@@ -72,19 +68,20 @@ public class OrderServiceImpl implements IOrderService
private OrderTakingServiceImpl orderTakingService;
@Autowired
private CustomerMapper customerMapper;
@Autowired
private SysConfigServiceImpl sysConfigService;
@Autowired
SendSmsUtil sendSmsUtil;
/**
* 查询订单
*
*
* @param id 订单主键
* @return 订单
*/
@Override
public Order selectOrderById(String id)
{
public Order selectOrderById(String id) {
Order order = orderMapper.selectOrderById(id);
order.setShop(shopMapper.selectShopById(order.getShopId()));
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
......@@ -94,27 +91,26 @@ public class OrderServiceImpl implements IOrderService
return order;
}
public Order selectById(String id){
public Order selectById(String id) {
return orderMapper.selectOrderById(id);
}
/**
* 查询订单列表
*
*
* @param order 订单
* @return 订单
*/
@Override
public List<Order> selectOrderList(OrderQuery order)
{
public List<Order> selectOrderList(OrderQuery order) {
List<Order> orders = orderMapper.selectOrderByQuery(order);
for (Order order1 : orders) {
order1.setShop(shopMapper.selectShopById(order1.getShopId()));
}
return orders;
}
public List<Order> selectOrderList(Order order)
{
public List<Order> selectOrderList(Order order) {
List<Order> orders = orderMapper.selectOrderList(order);
return orders;
......@@ -122,27 +118,24 @@ public class OrderServiceImpl implements IOrderService
/**
* 新增订单
*
*
* @param loginUser
* @param order 订单
* @param order 订单
* @return 结果
*/
@Override
@Transactional
public AjaxResult insertOrder(LoginUser loginUser, Order order)
{
public AjaxResult insertOrder(LoginUser loginUser, Order order) {
AjaxResult result = check(order);
if(HttpStatus.SUCCESS != (int)result.get(result.CODE_TAG)){
if (HttpStatus.SUCCESS != (int) result.get(result.CODE_TAG)) {
return result;
}
try{
checkBusinessTime(order.getShopId());
}catch (ServiceException e){
try {
checkBusinessTime(order.getShopId());
} catch (ServiceException e) {
return AjaxResult.error(e.getMessage());
}
order.setState(OrderStatusConstant.Unpaid);
order.setUserId(loginUser.getOpenId());
......@@ -153,24 +146,24 @@ public class OrderServiceImpl implements IOrderService
order.setOrderNo(getOrderNo(order.getSource()));
order.setUpdatedAt(new Date());
String machineId = null;
if(StringUtils.isEmpty(order.getMachineId())){
Machine machine =new Machine();
if (StringUtils.isEmpty(order.getMachineId())) {
Machine machine = new Machine();
machine.setShopId(Long.parseLong(order.getShopId()));
List<Machine> machines = machineMapper.selectMachineList(machine);
if(machines!=null &&!machines.isEmpty()){
if (machines != null && !machines.isEmpty()) {
Machine machine1 = machines.get(0);
if(!"1".equals(machine1.getState())){
if (!"1".equals(machine1.getState())) {
return AjaxResult.error("机器暂时不可用");
}
machineId = machine1.getId();
order.setMachineId(machineId);
}else{
} else {
return AjaxResult.error("该店铺暂无绑定机器");
}
}
List<OrderDetail> orderDetails = order.getOrderDetails();
if(orderDetails !=null && !orderDetails.isEmpty()){
if (orderDetails != null && !orderDetails.isEmpty()) {
// BigDecimal bigDecimal = new BigDecimal(0);
// for (OrderDetail orderDetail : orderDetails) {
// bigDecimal = bigDecimal.add(orderDetail.getRealAmount().multiply( new BigDecimal(orderDetail.getNum())));
......@@ -179,7 +172,7 @@ public class OrderServiceImpl implements IOrderService
// throw new ServiceException("价格计算出现了问题,请重新计算"+ bigDecimal.stripTrailingZeros().toString() );
// }
// order.setAmount(bigDecimal);
int i = orderMapper.insertOrder(order);
int i = orderMapper.insertOrder(order);
for (OrderDetail orderDetail : orderDetails) {
orderDetail.setOrderId(order.getId());
orderDetail.setCreatedAt(new Date());
......@@ -204,13 +197,13 @@ public class OrderServiceImpl implements IOrderService
String[] split = startTime.split(":");
String[] split1 = endTime.split(":");
Calendar startBusiness = Calendar.getInstance();
startBusiness.set(Calendar.HOUR_OF_DAY,Integer.parseInt(split[0]));
startBusiness.set(Calendar.MINUTE,Integer.parseInt(split[1]));
startBusiness.set(Calendar.HOUR_OF_DAY, Integer.parseInt(split[0]));
startBusiness.set(Calendar.MINUTE, Integer.parseInt(split[1]));
Calendar endBusiness = Calendar.getInstance();
endBusiness.set(Calendar.HOUR_OF_DAY,Integer.parseInt(split1[0]));
endBusiness.set(Calendar.MINUTE,Integer.parseInt(split1[1]));
endBusiness.set(Calendar.HOUR_OF_DAY, Integer.parseInt(split1[0]));
endBusiness.set(Calendar.MINUTE, Integer.parseInt(split1[1]));
long l = System.currentTimeMillis();
if(startBusiness.getTimeInMillis()>l||endBusiness.getTimeInMillis()<l){
if (startBusiness.getTimeInMillis() > l || endBusiness.getTimeInMillis() < l) {
throw new ServiceException("当前时间本店休息中,暂停点单~");
}
......@@ -218,13 +211,12 @@ public class OrderServiceImpl implements IOrderService
}
/**
*订单重写从这里开始,这里要承担大部分的业务逻辑,逻辑集中化处理
* 订单重写从这里开始,这里要承担大部分的业务逻辑,逻辑集中化处理
*/
@Override
public int updateOrder(Order order)
{
public int updateOrder(Order order) {
String state = order.getState();
switch (state){
switch (state) {
case OrderStatusConstant.Paid:
paidState(order);
break;
......@@ -266,6 +258,7 @@ public class OrderServiceImpl implements IOrderService
/**
* 部分退款
*
* @param order
*/
private void partialRefundState(Order order) {
......@@ -277,6 +270,7 @@ public class OrderServiceImpl implements IOrderService
* 制作完成 机器给我们
* 记录日志
* 极光推送
*
* @param order
*/
private void completedState(Order order) {
......@@ -292,6 +286,7 @@ public class OrderServiceImpl implements IOrderService
* 退款中
* 极光推送
* 推送给机器
*
* @param order
*/
private void refundingState(Order order) {
......@@ -304,6 +299,7 @@ public class OrderServiceImpl implements IOrderService
* 记录日志
* 发送给机器
* 极光推送
*
* @param order
*/
private void unpaidCancelState(Order order) {
......@@ -316,6 +312,7 @@ public class OrderServiceImpl implements IOrderService
/**
* 取餐中
* 极光推送
*
* @param order
*/
private void takingState(Order order) {
......@@ -329,16 +326,17 @@ public class OrderServiceImpl implements IOrderService
* 极光推送
* 消息记录
* 发送推送消息
*
* @param order
*/
private void productionCompletedState(Order order) {
orderOperationLogService.insertOrderOperationLog(order);
jiGuangPushService.pushOrderState(order);
wechatMessageService.insertWechatMessage(order.getUserId(),"制作完成,您的订单已经制作完成,现在可以去取餐啦!");
wechatMessageService.insertWechatMessage(order.getUserId(), "制作完成,您的订单已经制作完成,现在可以去取餐啦!");
sendMessageUtils.sendWxMsg(order);
Customer customer = customerMapper.selectCustomerById(order.getUserId());
if(!"1".equals(customer.getAllow())){
sendSmsUtil.sendSms(order.getUserPhone(),"SMS_243650242",null);
if (!"1".equals(customer.getAllow())) {
sendSmsUtil.sendSms(order.getUserPhone(), "SMS_243650242", null);
}
}
......@@ -349,12 +347,13 @@ public class OrderServiceImpl implements IOrderService
* 发送消息给安卓
* 消息记录
* 发送推送消息
*
* @param order
*/
private void productionState(Order order) {
orderOperationLogService.insertOrderOperationLog(order);
jiGuangPushService.pushOrderState(order);
wechatMessageService.insertWechatMessage(order.getUserId(),"制作提醒,您的订单已经开始制作,马上就能享受美味了!");
wechatMessageService.insertWechatMessage(order.getUserId(), "制作提醒,您的订单已经开始制作,马上就能享受美味了!");
sendMessageUtils.sendWxMsg(order);
}
......@@ -366,6 +365,7 @@ public class OrderServiceImpl implements IOrderService
* 发送给安卓
* 消息记录
* 发送推送消息
*
* @param order
*/
private void paidState(Order order) {
......@@ -373,31 +373,29 @@ public class OrderServiceImpl implements IOrderService
machineApiService.updateOrder(order);
//极光推送
jiGuangPushService.pushOrderState(order);
wechatMessageService.insertWechatMessage(order.getUserId(),"下单成功,您已经下单成功了~");
wechatMessageService.insertWechatMessage(order.getUserId(), "下单成功,您已经下单成功了~");
sendMessageUtils.sendWxMsg(order);
}
/**
* 批量删除订单
*
*
* @param ids 需要删除的订单主键
* @return 结果
*/
@Override
public int deleteOrderByIds(String[] ids)
{
public int deleteOrderByIds(String[] ids) {
return orderMapper.deleteOrderByIds(ids);
}
/**
* 删除订单信息
*
*
* @param id 订单主键
* @return 结果
*/
@Override
public int deleteOrderById(String id)
{
public int deleteOrderById(String id) {
return orderMapper.deleteOrderById(id);
}
......@@ -405,22 +403,28 @@ public class OrderServiceImpl implements IOrderService
public AjaxResult check(Order order) {
//验证订单状态
List<OrderDetail> orderDetails = order.getOrderDetails();
if(orderDetails==null ||orderDetails.isEmpty()){
if (orderDetails == null || orderDetails.isEmpty()) {
return AjaxResult.error("订单信息不能为空");
}
String orderLimit = sysConfigService.selectConfigByKey("goods.limit");
int countOfOrder = StringUtils.isEmpty(orderLimit) ? 9 : Integer.parseInt(orderLimit);
if (orderDetails.size() > countOfOrder) {
return AjaxResult.error(String.format("单次最多购买%s杯,请结算后再次下单", countOfOrder));
}
for (OrderDetail orderDetail : orderDetails) {
ShopGoodsSku shopGoodsSku = new ShopGoodsSku();
shopGoodsSku.setSkuId(Long.parseLong(orderDetail.getSkuId()));
shopGoodsSku.setShopId(Long.valueOf(order.getShopId()));
shopGoodsSku.setIsDeleted("0");
List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuMapper.selectShopGoodsSkuList(shopGoodsSku);
if(shopGoodsSkus ==null ||shopGoodsSkus.isEmpty()){
return AjaxResult.error("该商品已不存在:"+orderDetail.getGoodsName());
if (shopGoodsSkus == null || shopGoodsSkus.isEmpty()) {
return AjaxResult.error("本商品已不存在:" + orderDetail.getGoodsName());
}
ShopGoodsSku shopGoodsSku1 = shopGoodsSkus.get(0);
if(!"1".equals(shopGoodsSku1.getState())){
return AjaxResult.error("该商品所选种类已经告罄,请重新进行选择:"+orderDetail.getGoodsName());
if (!"1".equals(shopGoodsSku1.getState())) {
return AjaxResult.error("本商品已售罄或已经下架:" + orderDetail.getGoodsName());
}
}
return AjaxResult.success();
......@@ -433,7 +437,7 @@ public class OrderServiceImpl implements IOrderService
for (Order order : orders) {
order.setShop(shopMapper.selectShopById(order.getShopId()));
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
order.setOrderDetails(JSONArray.parseArray(orderSnapshot.getSnapshot(),OrderDetail.class));
order.setOrderDetails(JSONArray.parseArray(orderSnapshot.getSnapshot(), OrderDetail.class));
}
return orders;
}
......@@ -442,16 +446,16 @@ public class OrderServiceImpl implements IOrderService
@Transactional
public int cancel(String orderId) {
Order order = orderMapper.selectOrderById(orderId);
if(OrderStatusConstant.Unpaid.equals(order.getState())){
if (OrderStatusConstant.Unpaid.equals(order.getState())) {
order.setState("8");
order.setUpdatedAt(new Date());
this.updateOrder(order);
}else if(OrderStatusConstant.Paid.equals(order.getState())){
} else if (OrderStatusConstant.Paid.equals(order.getState())) {
order.setState("9");
order.setUpdatedAt(new Date());
this.updateOrder(order);
}else{
} else {
throw new ServiceException("该订单不允许取消");
}
......@@ -459,70 +463,71 @@ public class OrderServiceImpl implements IOrderService
}
/**
* 获取机器顺序号
*
* @param shopId
* @return
*/
private String getOrderNum(String shopId){
private String getOrderNum(String shopId) {
Calendar calendar = Calendar.getInstance();
String key = calendar.getTime().toString().substring(0,3);
String key = calendar.getTime().toString().substring(0, 3);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = simpleDateFormat.format(new Date());
String redisKey = "shopId"+format+shopId;
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey,SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
if(0 == redisAtomicInteger.get()){
redisAtomicInteger.set((int)(1000*Math.random()));
String redisKey = "shopId" + format + shopId;
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey, SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
if (0 == redisAtomicInteger.get()) {
redisAtomicInteger.set((int) (1000 * Math.random()));
}
redisAtomicInteger.expire(1, TimeUnit.DAYS);
int andIncrement = redisAtomicInteger.getAndAdd(3);
return key+String.format("%03d",andIncrement);
return key + String.format("%03d", andIncrement);
}
//获取订单号
public String getOrderNo(Integer source){
public String getOrderNo(Integer source) {
String channel = "M";
if(source !=null){
if(source == 1){
channel="A";
}else if(source ==2){
channel="B";
if (source != null) {
if (source == 1) {
channel = "A";
} else if (source == 2) {
channel = "B";
}
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHH");
String format = simpleDateFormat.format(new Date());
format = format.substring(2);
String key = "orderNo";
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(key,SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(key, SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
int andIncrement = redisAtomicInteger.getAndIncrement();
if(andIncrement>9999){
if (andIncrement > 9999) {
redisAtomicInteger.set(0);
andIncrement = 0;
}
String format1 = String.format("%04d", andIncrement);
int randomNumber = new Random().nextInt(99);
return "N"+format+channel+format1+randomNumber;
return "N" + format + channel + format1 + randomNumber;
}
public List<JSONObject> getOrderInfo(String machineCode) {
public List<JSONObject> getOrderInfo(String machineCode) {
Machine machine = machineMapper.selectMachineByCode(machineCode);
List<String> status = Arrays.asList("2","3","4");
List<String> status = Arrays.asList("2", "3", "4");
List<Order> orders = orderMapper.selectOrder(status, machine.getId());
Map<String, List<Order>> collect = orders.stream().collect(Collectors.groupingBy(Order::getState));
List<JSONObject> objects = new ArrayList<>();
for(String key:collect.keySet()){
JSONObject jsonObject =new JSONObject();
for (String key : collect.keySet()) {
JSONObject jsonObject = new JSONObject();
objects.add(jsonObject);
jsonObject.put("state",key);
jsonObject.put("state", key);
List<Order> orders1 = collect.get(key);
List<JSONObject> jsonObjects = new ArrayList<>();
jsonObject.put("orders",jsonObjects);
jsonObject.put("orders", jsonObjects);
for (Order order : orders1) {
JSONObject jsonObject1 = new JSONObject();
jsonObjects.add(jsonObject1);
jsonObject1.put("orderId",order.getId());
jsonObject1.put("orderNumber",order.getOrderNum());
jsonObject1.put("orderNo",order.getOrderNo());
jsonObject1.put("orderId", order.getId());
jsonObject1.put("orderNumber", order.getOrderNum());
jsonObject1.put("orderNo", order.getOrderNo());
}
}
return objects;
......@@ -532,20 +537,20 @@ public class OrderServiceImpl implements IOrderService
public String refundOrder(String orderId) {
Order order = orderMapper.selectOrderById(orderId);
List<String> status = Arrays.asList("2","3");
if(status.contains(order.getState())){
List<String> status = Arrays.asList("2", "3");
if (status.contains(order.getState())) {
//todo 创建退款单,进行退款
}else{
} else {
//todo 创建退款单
}
return null;
}
public Map<String,String> getMyFristOrder(String openId,String shopId) {
List<String> status = Arrays.asList("2","3","4");
Order order = orderMapper.selectHomeByUserId(openId,status,shopId);
if(order ==null){
public Map<String, String> getMyFristOrder(String openId, String shopId) {
List<String> status = Arrays.asList("2", "3", "4");
Order order = orderMapper.selectHomeByUserId(openId, status, shopId);
if (order == null) {
return null;
}
OrderDetail orderDetail = new OrderDetail();
......@@ -553,18 +558,18 @@ public class OrderServiceImpl implements IOrderService
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
order.setOrderDetails(orderDetails);
String waitTime = getWaitTimeByOrderId(order.getId());
Map<String,String> map =new HashMap<>();
map.put("waitTime",waitTime);
map.put("pickCode",order.getPickCode());
map.put("orderNum",order.getOrderNum());
map.put("state",order.getState());
Map<String, String> map = new HashMap<>();
map.put("waitTime", waitTime);
map.put("pickCode", order.getPickCode());
map.put("orderNum", order.getOrderNum());
map.put("state", order.getState());
return map;
}
public String getWaitTime(Order order) {
String shopId = order.getShopId();
List<String> status = Arrays.asList(OrderStatusConstant.Paid,OrderStatusConstant.production);
List<String> status = Arrays.asList(OrderStatusConstant.Paid, OrderStatusConstant.production);
List<Order> orders = orderMapper.selectOrderByShopId(status, shopId);
List<OrderDetail> list = new ArrayList<>();
list.addAll(order.getOrderDetails());
......@@ -572,57 +577,57 @@ public class OrderServiceImpl implements IOrderService
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(order1.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
if(CollectionUtils.isEmpty(orderDetails)){
if (CollectionUtils.isEmpty(orderDetails)) {
}else{
} else {
list.addAll(orderDetails);
}
}
Long takeTimeCount =0L;
Long takeTimeCount = 0L;
for (OrderDetail orderDetail : list) {
Goods goods = goodsMapper.selectGoodsById(orderDetail.getGoodsId());
if(goods ==null){
if (goods == null) {
continue;
}
Long takeTime = goods.getTakeTime();
takeTime = Integer.parseInt(orderDetail.getNum())*takeTime;
takeTimeCount+=takeTime;
takeTime = Integer.parseInt(orderDetail.getNum()) * takeTime;
takeTimeCount += takeTime;
}
return String.valueOf((int)(takeTimeCount/60));
return String.valueOf((int) (takeTimeCount / 60));
}
public String getWaitTimeByOrderId(Long orderId) {
List<String> status = Arrays.asList(OrderStatusConstant.Paid,OrderStatusConstant.production);
List<String> status = Arrays.asList(OrderStatusConstant.Paid, OrderStatusConstant.production);
List<Order> orders = orderMapper.selectBeforeOrder(status, orderId);
List<OrderDetail> list = new ArrayList<>();
for (Order order1 : orders) {
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(order1.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
if(CollectionUtils.isEmpty(orderDetails)){
if (CollectionUtils.isEmpty(orderDetails)) {
}else{
} else {
list.addAll(orderDetails);
}
}
Long takeTimeCount =0L;
Long takeTimeCount = 0L;
for (OrderDetail orderDetail : list) {
Goods goods = goodsMapper.selectGoodsById(orderDetail.getGoodsId());
if(goods!=null){
if (goods != null) {
Long takeTime = goods.getTakeTime();
takeTime = Integer.parseInt(orderDetail.getNum())*takeTime;
takeTimeCount+=takeTime;
takeTime = Integer.parseInt(orderDetail.getNum()) * takeTime;
takeTimeCount += takeTime;
}
}
return String.valueOf((int)(takeTimeCount/60));
return String.valueOf((int) (takeTimeCount / 60));
}
public List<GoodsVo> getNextOrder(String orderId,String shopId) {
public List<GoodsVo> getNextOrder(String orderId, String shopId) {
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(Long.parseLong(orderId));
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
......@@ -630,36 +635,35 @@ public class OrderServiceImpl implements IOrderService
OrderTakingVo infoByShop = orderTakingService.getInfoByShop(shopId);
List<CategoryVo> categorys = infoByShop.getCategorys();
List<GoodsVo> ccs = new ArrayList<>();
if(categorys !=null && !categorys.isEmpty()){
if (categorys != null && !categorys.isEmpty()) {
for (CategoryVo category : categorys) {
if(category.getId()==0 ){
if (category.getId() == 0) {
continue;
}
List<GoodsVo> goods = category.getGoods();
if(goods==null ||goods.isEmpty()){
if (goods == null || goods.isEmpty()) {
continue;
}
for (GoodsVo good : goods) {
List<SkuVo> skuVoList = new ArrayList<>();
if(good.getSkus()==null ||good.getSkus().isEmpty()){
if (good.getSkus() == null || good.getSkus().isEmpty()) {
continue;
}
for (SkuVo skus : good.getSkus()) {
if(skuIds.contains(skus.getSkuId())){
if (skuIds.contains(skus.getSkuId())) {
skuVoList.add(skus);
}
}
if(!skuVoList.isEmpty()){
if (!skuVoList.isEmpty()) {
ccs.add(good);
good.setSkus(skuVoList);
}
}
}
}
return ccs;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment