wxApp后端订单用户商品表开发
This commit is contained in:
parent
1ec48d14b6
commit
005063d2e3
|
@ -0,0 +1,42 @@
|
||||||
|
package com.bigdata.wxappserver.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bigdata.wxappserver.service.GoodsService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/08/29/19:53
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("goods")
|
||||||
|
@Slf4j
|
||||||
|
public class GoodsController {
|
||||||
|
@Autowired
|
||||||
|
GoodsService goodsService;
|
||||||
|
|
||||||
|
@RequestMapping("addOrUpdate")
|
||||||
|
public JSONObject addOrUpdate(@RequestBody JSONObject jsonObject){
|
||||||
|
return goodsService.addOrUpdate(jsonObject);
|
||||||
|
}
|
||||||
|
@RequestMapping("delete")
|
||||||
|
public JSONObject delete(@RequestParam("id")Integer id){
|
||||||
|
return goodsService.delete(id);
|
||||||
|
// return new JSONObject().fluentPut("success",goodsService.removeById(id));
|
||||||
|
}
|
||||||
|
@RequestMapping("getById")
|
||||||
|
public JSONObject queryById(@RequestParam("id") Integer id){
|
||||||
|
return goodsService.queryById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("loadData")
|
||||||
|
public JSONObject list(){
|
||||||
|
return new JSONObject().fluentPut("data",goodsService.list());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
package com.bigdata.wxappserver.controller;
|
package com.bigdata.wxappserver.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.bigdata.wxappserver.service.OrderService;
|
import com.bigdata.wxappserver.service.OrderService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +31,16 @@ public class OrderController {
|
||||||
@RequestMapping("loadData")
|
@RequestMapping("loadData")
|
||||||
public JSONObject list(@RequestBody JSONObject jsonObject){
|
public JSONObject list(@RequestBody JSONObject jsonObject){
|
||||||
return orderService.list(jsonObject);
|
return orderService.list(jsonObject);
|
||||||
|
|
||||||
|
}
|
||||||
|
@RequestMapping("getById")
|
||||||
|
public JSONObject queryById(@RequestParam("id") Integer id){
|
||||||
|
return orderService.queryById(id);
|
||||||
|
}
|
||||||
|
@RequestMapping("delete")
|
||||||
|
public JSONObject delete(@RequestParam("id")Integer id){
|
||||||
|
// return new JSONObject().fluentPut("success",orderService.removeById(id));
|
||||||
|
return orderService.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.bigdata.wxappserver.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bigdata.wxappserver.service.UserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/08/29/22:59
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping("user")
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
@RequestMapping("addOrUpdate")
|
||||||
|
public JSONObject addOrUpdate(@RequestBody JSONObject jsonObject){
|
||||||
|
return userService.addOrUpdate(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("loadData")
|
||||||
|
public JSONObject list(@RequestBody JSONObject jsonObject){
|
||||||
|
return new JSONObject().fluentPut("data",userService.list());
|
||||||
|
|
||||||
|
}
|
||||||
|
@RequestMapping("getById")
|
||||||
|
public JSONObject queryById(@RequestParam("id") Integer id){
|
||||||
|
return userService.queryById(id);
|
||||||
|
}
|
||||||
|
@RequestMapping("delete")
|
||||||
|
public JSONObject delete(@RequestParam("id")Integer id){
|
||||||
|
return userService.delete(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ public class Goods extends Base {
|
||||||
/**
|
/**
|
||||||
* 商品图片路径
|
* 商品图片路径
|
||||||
*/
|
*/
|
||||||
private String image;
|
private String goodImage;
|
||||||
/**
|
/**
|
||||||
* 商品描述
|
* 商品描述
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,10 +1,45 @@
|
||||||
package com.bigdata.wxappserver.service;
|
package com.bigdata.wxappserver.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.bigdata.wxappserver.entity.Goods;
|
import com.bigdata.wxappserver.entity.Goods;
|
||||||
|
import com.bigdata.wxappserver.entity.Order;
|
||||||
|
import com.bigdata.wxappserver.entity.User;
|
||||||
import com.bigdata.wxappserver.mapper.GoodsMapper;
|
import com.bigdata.wxappserver.mapper.GoodsMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {
|
public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
||||||
|
Goods good = jsonObject.toJavaObject(Goods.class);
|
||||||
|
if (good == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "参数错误");
|
||||||
|
}
|
||||||
|
// TODO 判空
|
||||||
|
boolean success = saveOrUpdate(good);
|
||||||
|
return new JSONObject().fluentPut("message", "success").fluentPut("success", success);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject queryById(Integer id) {
|
||||||
|
if(id==null){
|
||||||
|
return new JSONObject().fluentPut("success",false).fluentPut("message","缺少ID");
|
||||||
|
}
|
||||||
|
Goods goods = getById(id);
|
||||||
|
return new JSONObject().fluentPut("data",goods);
|
||||||
|
}
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public JSONObject delete(Integer id) {
|
||||||
|
if(id==null){
|
||||||
|
return new JSONObject().fluentPut("success",false).fluentPut("message","缺少Id");
|
||||||
|
}
|
||||||
|
boolean success = removeById(id);
|
||||||
|
if(success){
|
||||||
|
return new JSONObject().fluentPut("success",true);
|
||||||
|
}else{
|
||||||
|
return new JSONObject().fluentPut("success",false).fluentPut("message","出现未知错误,请联系管理员!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,22 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bigdata.wxappserver.entity.Goods;
|
||||||
import com.bigdata.wxappserver.entity.Order;
|
import com.bigdata.wxappserver.entity.Order;
|
||||||
|
import com.bigdata.wxappserver.entity.User;
|
||||||
import com.bigdata.wxappserver.enums.OrderStatusEnum;
|
import com.bigdata.wxappserver.enums.OrderStatusEnum;
|
||||||
import com.bigdata.wxappserver.mapper.OrderMapper;
|
import com.bigdata.wxappserver.mapper.OrderMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.fasterxml.jackson.databind.type.LogicalType.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
*
|
*
|
||||||
|
@ -25,35 +32,41 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
||||||
Order order = jsonObject.toJavaObject(Order.class);
|
Order order = jsonObject.toJavaObject(Order.class);
|
||||||
if (order==null){
|
if (order == null) {
|
||||||
return new JSONObject().fluentPut("success",false).fluentPut("message","参数错误");
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "参数错误");
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasLength(order.getAddress())) {
|
||||||
|
User user = userService.getById(order.getUserId());
|
||||||
|
order.setAddress(user.getAddress());
|
||||||
}
|
}
|
||||||
// TODO 判空
|
// TODO 判空
|
||||||
boolean success = saveOrUpdate(order);
|
boolean success = saveOrUpdate(order);
|
||||||
return new JSONObject().fluentPut("message","success").fluentPut("success",success);
|
return new JSONObject().fluentPut("message", "success").fluentPut("success", success);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject list(JSONObject jsonObject){
|
public JSONObject list(JSONObject jsonObject) {
|
||||||
String userId = jsonObject.getString("userId");
|
String userId = jsonObject.getString("userId");
|
||||||
Integer currentPage = jsonObject.getInteger("currentPage");
|
// Integer currentPage = jsonObject.getInteger("currentPage");
|
||||||
Integer pageSize = jsonObject.getInteger("pageSize");
|
// Integer pageSize = jsonObject.getInteger("pageSize");
|
||||||
IPage<Order> page=new Page<>(currentPage,pageSize);
|
// IPage<Order> page = new Page<>(currentPage, pageSize);
|
||||||
LambdaQueryWrapper<Order> wrapper=new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(userId!=null,Order::getUserId,userId);
|
wrapper.eq(userId != null, Order::getUserId, userId);
|
||||||
IPage<Order> orderIPage = page(page, wrapper);
|
// IPage<Order> orderIPage = page(page, wrapper);
|
||||||
dealList(orderIPage.getRecords());
|
List<Order> list = list(wrapper);
|
||||||
JSONObject returnData=new JSONObject();
|
dealList(list);
|
||||||
returnData.fluentPut("data",orderIPage.getRecords())
|
JSONObject returnData = new JSONObject();
|
||||||
.fluentPut("total",orderIPage.getTotal())
|
returnData.fluentPut("data", list);
|
||||||
.fluentPut("current",orderIPage.getCurrent());
|
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealList(List<Order> records) {
|
private void dealList(List<Order> records) {
|
||||||
if(CollectionUtils.isEmpty(records)){
|
if (CollectionUtils.isEmpty(records)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Order record : records) {
|
for (Order record : records) {
|
||||||
|
@ -62,4 +75,27 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public JSONObject queryById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少ID");
|
||||||
|
}
|
||||||
|
Order order = getById(id);
|
||||||
|
dealList(Collections.singletonList(order));
|
||||||
|
return new JSONObject().fluentPut("data", order);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public JSONObject delete(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少Id");
|
||||||
|
}
|
||||||
|
boolean success = removeById(id);
|
||||||
|
if (success) {
|
||||||
|
return new JSONObject().fluentPut("success", true);
|
||||||
|
} else {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "出现未知错误,请联系管理员!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,80 @@
|
||||||
package com.bigdata.wxappserver.service;
|
package com.bigdata.wxappserver.service;
|
||||||
|
|
||||||
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.bigdata.wxappserver.entity.User;
|
import com.bigdata.wxappserver.entity.User;
|
||||||
import com.bigdata.wxappserver.mapper.UserMapper;
|
import com.bigdata.wxappserver.mapper.UserMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService extends ServiceImpl<UserMapper, User> {
|
public class UserService extends ServiceImpl<UserMapper, User> {
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
||||||
|
User user = jsonObject.toJavaObject(User.class);
|
||||||
|
if (user == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "参数错误");
|
||||||
|
}
|
||||||
|
List<User> userList = list();
|
||||||
|
List<String> openIdList = userList.stream().map(User::getOpenId).collect(Collectors.toList());
|
||||||
|
if (user.getId() == null && !CollectionUtils.isEmpty(openIdList) && openIdList.contains(user.getOpenId())) {
|
||||||
|
return new JSONObject().fluentPut("message", "该用户已存在").fluentPut("success", false);
|
||||||
|
}
|
||||||
|
// TODO 判空
|
||||||
|
boolean success = saveOrUpdate(user);
|
||||||
|
return new JSONObject().fluentPut("success", success);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject list(JSONObject jsonObject) {
|
||||||
|
String userId = jsonObject.getString("userId");
|
||||||
|
Integer currentPage = jsonObject.getInteger("currentPage");
|
||||||
|
Integer pageSize = jsonObject.getInteger("pageSize");
|
||||||
|
IPage<User> page = new Page<>(currentPage, pageSize);
|
||||||
|
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(userId != null, User::getId, userId);
|
||||||
|
IPage<User> userIPage = page(page, wrapper);
|
||||||
|
dealList(userIPage.getRecords());
|
||||||
|
JSONObject returnData = new JSONObject();
|
||||||
|
returnData.fluentPut("data", userIPage.getRecords())
|
||||||
|
.fluentPut("total", userIPage.getTotal())
|
||||||
|
.fluentPut("current", userIPage.getCurrent());
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dealList(List<User> records) {
|
||||||
|
if (CollectionUtils.isEmpty(records)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public JSONObject delete(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少Id");
|
||||||
|
}
|
||||||
|
boolean success = removeById(id);
|
||||||
|
if (success) {
|
||||||
|
return new JSONObject().fluentPut("success", true);
|
||||||
|
} else {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "出现未知错误,请联系管理员!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject queryById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少ID");
|
||||||
|
}
|
||||||
|
User user = getById(id);
|
||||||
|
return new JSONObject().fluentPut("data", user);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ spring:
|
||||||
username: root
|
username: root
|
||||||
password: nWZpHMb8mNxWE5Xk
|
password: nWZpHMb8mNxWE5Xk
|
||||||
server:
|
server:
|
||||||
port: 8088
|
port: 8080
|
||||||
|
|
||||||
# Mybatis-plus??
|
# Mybatis-plus配置
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath*:/mapper/*Mapper.xml
|
mapper-locations: classpath*:/mapper/*Mapper.xml
|
||||||
configuration:
|
configuration:
|
||||||
|
|
Loading…
Reference in New Issue