订单查询与其他表初始化
This commit is contained in:
parent
eca60d0d87
commit
1ec48d14b6
|
@ -24,7 +24,11 @@ public class OrderController {
|
|||
@RequestMapping("addOrUpdate")
|
||||
public JSONObject addOrUpdate(@RequestBody JSONObject jsonObject){
|
||||
return orderService.addOrUpdate(jsonObject);
|
||||
}
|
||||
|
||||
@RequestMapping("loadData")
|
||||
public JSONObject list(@RequestBody JSONObject jsonObject){
|
||||
return orderService.list(jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.bigdata.wxappserver.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Base {
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.bigdata.wxappserver.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@TableName("goods")
|
||||
public class Goods extends Base {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String goodName;
|
||||
/**
|
||||
* 商品价格
|
||||
*/
|
||||
private BigDecimal goodPrice;
|
||||
/**
|
||||
* 商品库存
|
||||
*/
|
||||
private Integer goodStock;
|
||||
/**
|
||||
* 商品图片路径
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 商品描述
|
||||
*/
|
||||
private String goodDetail;
|
||||
|
||||
}
|
|
@ -15,21 +15,25 @@ import java.util.Date;
|
|||
*/
|
||||
@TableName("common_order")
|
||||
@Data
|
||||
public class Order {
|
||||
public class Order extends Base {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String username;
|
||||
private String phone;
|
||||
|
||||
private Integer goodId;
|
||||
private Integer userId;
|
||||
private Integer goodsId;
|
||||
private String address;
|
||||
private LocalDateTime deliveryTime;
|
||||
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
/**
|
||||
* 订单状态 @see
|
||||
*/
|
||||
private Integer status;
|
||||
@TableField(exist = false)
|
||||
private String statusDescription;
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
private Integer nums;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.bigdata.wxappserver.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("common_user")
|
||||
public class User extends Base{
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 微信用户唯一ID
|
||||
*/
|
||||
private String openId;
|
||||
/**
|
||||
* 用户电话
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 用户地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.bigdata.wxappserver.enums;
|
||||
|
||||
import com.bigdata.wxappserver.utils.EnumUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.swing.text.html.Option;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
public enum OrderStatusEnum {
|
||||
|
||||
NON_PAYMENT(1,"待付款"),
|
||||
NON_ORDER(2,"待接单"),
|
||||
ORDERED(3,"已接单"),
|
||||
DELIVERY(4,"派送中"),
|
||||
FINISHED(5,"已完成"),
|
||||
CANCELED(6,"已取消");
|
||||
private Integer id;
|
||||
private String description;
|
||||
|
||||
OrderStatusEnum(Integer id,String description){
|
||||
this.id=id;
|
||||
this.description=description;
|
||||
}
|
||||
|
||||
public static Optional<OrderStatusEnum> valueOf(Integer id){
|
||||
return EnumUtil.getEnumObject(OrderStatusEnum.class,e-> Objects.equals(e.getId(),id));
|
||||
}
|
||||
|
||||
public static String describe(Integer id){
|
||||
return valueOf(id).map(OrderStatusEnum::getDescription).orElse("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.bigdata.wxappserver.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bigdata.wxappserver.entity.Goods;
|
||||
|
||||
public interface GoodsMapper extends BaseMapper<Goods> {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.bigdata.wxappserver.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bigdata.wxappserver.entity.User;
|
||||
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.bigdata.wxappserver.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bigdata.wxappserver.entity.Goods;
|
||||
import com.bigdata.wxappserver.mapper.GoodsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {
|
||||
}
|
|
@ -2,10 +2,18 @@ package com.bigdata.wxappserver.service;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bigdata.wxappserver.entity.Order;
|
||||
import com.bigdata.wxappserver.enums.OrderStatusEnum;
|
||||
import com.bigdata.wxappserver.mapper.OrderMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
|
@ -17,7 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
||||
Order order = jsonObject.toJavaObject(Order.class);
|
||||
if (order==null){
|
||||
|
@ -27,4 +35,31 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
|||
boolean success = saveOrUpdate(order);
|
||||
return new JSONObject().fluentPut("message","success").fluentPut("success",success);
|
||||
}
|
||||
|
||||
public JSONObject list(JSONObject jsonObject){
|
||||
String userId = jsonObject.getString("userId");
|
||||
Integer currentPage = jsonObject.getInteger("currentPage");
|
||||
Integer pageSize = jsonObject.getInteger("pageSize");
|
||||
IPage<Order> page=new Page<>(currentPage,pageSize);
|
||||
LambdaQueryWrapper<Order> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(userId!=null,Order::getUserId,userId);
|
||||
IPage<Order> orderIPage = page(page, wrapper);
|
||||
dealList(orderIPage.getRecords());
|
||||
JSONObject returnData=new JSONObject();
|
||||
returnData.fluentPut("data",orderIPage.getRecords())
|
||||
.fluentPut("total",orderIPage.getTotal())
|
||||
.fluentPut("current",orderIPage.getCurrent());
|
||||
return returnData;
|
||||
}
|
||||
|
||||
private void dealList(List<Order> records) {
|
||||
if(CollectionUtils.isEmpty(records)){
|
||||
return;
|
||||
}
|
||||
for (Order record : records) {
|
||||
record.setStatusDescription(OrderStatusEnum.describe(record.getStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.bigdata.wxappserver.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bigdata.wxappserver.entity.User;
|
||||
import com.bigdata.wxappserver.mapper.UserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserService extends ServiceImpl<UserMapper, User> {
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.bigdata.wxappserver.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 枚举工具类
|
||||
*/
|
||||
public class EnumUtil {
|
||||
|
||||
private static Map<Class,Object> map=new ConcurrentHashMap<>(16);
|
||||
|
||||
public static <T> Optional<T> getEnumObject(Class<T> clazz, Predicate<T> predicate){
|
||||
if(!clazz.isEnum()){
|
||||
return Optional.empty();
|
||||
}
|
||||
Object object = map.get(clazz);
|
||||
T[] tArr=null;
|
||||
if(object ==null){
|
||||
tArr = clazz.getEnumConstants();
|
||||
map.put(clazz,tArr);
|
||||
}else{
|
||||
tArr= (T[]) object;
|
||||
}
|
||||
return Arrays.stream(tArr).filter(predicate).findFirst();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue