新增添加订单接口
This commit is contained in:
parent
c3b9ea95d9
commit
3cd3baac2e
|
@ -6,9 +6,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||
|
||||
/**
|
||||
* 全局跨域配置
|
||||
*
|
||||
*
|
||||
* @author bsz
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.cj.jiaqingjiayi.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
/**
|
||||
* Spring MVC Json 配置
|
||||
*/
|
||||
@JsonComponent
|
||||
public class JsonConfig {
|
||||
|
||||
/**
|
||||
* 添加 Long 转 json 精度丢失的配置
|
||||
*/
|
||||
@Bean
|
||||
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
module.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
objectMapper.registerModule(module);
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,22 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.*;
|
||||
import com.alipay.api.domain.AlipayTradeCreateModel;
|
||||
import com.alipay.api.domain.GoodsDetail;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.request.AlipayTradeCreateRequest;
|
||||
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.contant.UserConstant;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.mapper.UserMapper;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.utils.RandomNumberGenerator;
|
||||
|
@ -21,17 +24,16 @@ import io.swagger.annotations.Api;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
@Api(tags = "支付宝接口")
|
||||
@RestController
|
||||
@RequestMapping("/Alipay")
|
||||
|
@ -58,11 +60,12 @@ public class AlipayController {
|
|||
|
||||
/**
|
||||
* 解析code获取open_id和token
|
||||
*
|
||||
* @return aaa
|
||||
* @throws AlipayApiException 支付宝api异常
|
||||
*/
|
||||
@GetMapping("/parseCode")
|
||||
public BaseResponse<User> login(String authcode, HttpServletRequest req) throws AlipayApiException {
|
||||
public BaseResponse<User> login(String authCode, HttpServletRequest req) throws AlipayApiException {
|
||||
String privateKey = appPrivateKey;
|
||||
String alipayPublicKey = PublicKey;
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
|
@ -78,7 +81,7 @@ public class AlipayController {
|
|||
alipayConfig.setSignType("RSA2");
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
|
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
request.setCode(authcode);
|
||||
request.setCode(authCode);
|
||||
request.setGrantType("authorization_code");
|
||||
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
|
||||
// System.out.println(response.getBody());打印所有响应
|
||||
|
@ -97,16 +100,93 @@ public class AlipayController {
|
|||
user.setUserPassword("123456");
|
||||
user.setAvatarUrl(StringUtils.isAnyBlank(response1.getAvatar()) ? "https://tfs.alipayobjects.com/images/partner/ATuihpR50zu7UAAAAAAAAAAAAADtl2AA" : response1.getAvatar());
|
||||
userMapper.insert(user);
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,user);
|
||||
return ResultUtils.success(user,"注册成功");
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, user);
|
||||
return ResultUtils.success(user, "注册成功");
|
||||
}
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
|
||||
return ResultUtils.success(oid,"登录成功");
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, oid);
|
||||
return ResultUtils.success(oid, "登录成功");
|
||||
}
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE,oid);
|
||||
return ResultUtils.success(oid,"登录成功");
|
||||
req.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, oid);
|
||||
return ResultUtils.success(oid, "登录成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/trade")
|
||||
public BaseResponse<String> AlipayTradeCreate() throws AlipayApiException {
|
||||
|
||||
// 初始化SDK
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
|
||||
// 构造请求参数以调用接口
|
||||
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
|
||||
AlipayTradeCreateModel model = new AlipayTradeCreateModel();
|
||||
|
||||
// 获取当前时间的秒级时间戳(去掉年、月、日的前缀)
|
||||
String timePart = String.valueOf(System.currentTimeMillis() / 1000).substring(4);
|
||||
// 生成两位随机数
|
||||
String randomPart = String.format("%02d", new Random().nextInt(100));
|
||||
String orders = timePart + randomPart;
|
||||
// 设置商户订单号
|
||||
|
||||
model.setOutTradeNo(orders);
|
||||
// 设置订单总金额
|
||||
model.setTotalAmount("88.88");
|
||||
// 设置订单标题
|
||||
model.setSubject("Iphone6 16G");
|
||||
// 设置产品码
|
||||
model.setProductCode("JSAPI_PAY");
|
||||
// 设置卖家支付宝用户ID
|
||||
model.setSellerId("2088721037774480");
|
||||
// 设置买家支付宝用户唯一标识
|
||||
model.setBuyerOpenId("2088722037764824");
|
||||
// 设置小程序支付中
|
||||
model.setOpAppId("2021004144652242");
|
||||
// 设置订单附加信息
|
||||
model.setBody("Iphone6 16G");
|
||||
|
||||
// 设置订单包含的商品列表信息
|
||||
List<GoodsDetail> goodsDetail = new ArrayList<>();
|
||||
GoodsDetail goodsDetail0 = new GoodsDetail();
|
||||
goodsDetail0.setOutSkuId("outSku_01");
|
||||
goodsDetail0.setGoodsName("ipad");
|
||||
goodsDetail0.setAlipayGoodsId("20010001");
|
||||
goodsDetail0.setQuantity(10L);
|
||||
goodsDetail0.setPrice("2000");
|
||||
goodsDetail0.setOutItemId("outItem_01");
|
||||
goodsDetail0.setGoodsId("apple-01");
|
||||
goodsDetail0.setGoodsCategory("34543238");
|
||||
goodsDetail0.setCategoriesTree("124868003|126232002|126252004");
|
||||
goodsDetail0.setBody("特价手机");
|
||||
goodsDetail0.setShowUrl("http://www.alipay.com/xxx.jpg");
|
||||
goodsDetail.add(goodsDetail0);
|
||||
model.setGoodsDetail(goodsDetail);
|
||||
|
||||
request.setBizModel(model);
|
||||
|
||||
AlipayTradeCreateResponse response = alipayClient.execute(request);
|
||||
System.out.println(response.getBody());
|
||||
|
||||
String tradeNo = "";
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
tradeNo = response.getTradeNo();
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ResultUtils.success(tradeNo);
|
||||
}
|
||||
|
||||
private static AlipayConfig getAlipayConfig() {
|
||||
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCrh54evp6VX68kLvmWybc945JbHaJDRJf6bDSKNwQfCkvEZxfOwYTGXu7XfZq2G/qmFJ6Xp9KxV0yYrxPwjXwPMU4E78/ZaMZ44iSTSq+qvMJMBR7PJOX1MkW7EFfhUPmb+5S0KQurjMQadY4b2VxeHwVxTRPKAdsm0tnfgN8/pO7TfpyGOWX5dRSIruQ3c+MFmJOy0cSZZ4tGlidqZDS9v4YJpmw3u5dX4BvGKtNMPaAnxSpLCDp1fd/vh6ROl71QkLFR+3mNQcwvDOGNJ2Rq78bgfkIVp0BBMySk5Mfv6kunh0QMaxK8wi+Y9swv7Iiyy7U2/zrBvA+1i3e5ctH9AgMBAAECggEBAJSiNrTjbp13RVewUNyFvIAnc4n62sE5bgw0uS5PUAXpsQ/mWW3yqLAQURxvnaFSC1bgpTA630qGoDvp8fhPUYIEslt6xnvY26qiIxly7Vegqyiegzzx90YKIvxexBfdR/4O+aNHsfIcT02yMcsWBYEVlmzAYnZ4N0OkD+EpVcpaIBv2HwGsJnczz41GQVl9GX2DOL8j8+eSWhZM0Jq3d1ksgcfUHH1TT12XCbEE3fKJEMKKlrjVPrtTb+v9m6t0okOgjW+z+IR0zY1HBR92yC+0/CP4FfkbGBhKNxsmbyU4ilTmKINHMy40bqGqrEYo+LBzhEKBT82eMbg9cJbL68ECgYEA37dP5hWEfuTWAoAwduI6OW8kTwxNddIigzTV3qlqEeo21K6RQOOTeYKXrpMmYG65MU5J3xF7AYyhb3rMpega++22Qybxlrme88hqe0s/DeSToG2mw1zYLkkHb5+oT05fCOlLmFGPeLRBfJTxjM6wPNX/1NvGOEVC9DekXuauWZECgYEAxEhmSne07LD6J2sYqsbmOb0zdOpCNT0a+7SomZwiMpVFcsxFvZhYJlcLwyR2m3deLphxwQBPbyxe8TtOZST7P7APpoeI4c0t6PL44vG3eUh+GHFVyf1dbLwMGa9gQ0JFRwBH5iDD2hfnTNfmcNUYzBRHZQK60FFlPCd566hOG60CgYBNVNJbmEiKjJOlnaYjEiRKQi7s3DXSambfr93V7/3oX2vArO8s3P3XXNsNz3POlbeSYZuLbkF00aXkITCokMjzGMKOB+Iu1c8qObcFE4eiR8b4B69DjM51gWz+mtPVRiP3sp0c8+SCNt0EMYAlyjSFcvvSGn40aUyxmqJI47iU4QKBgFYStaCkO9eriBcvFKMXE7BwMpdrftsfz6xfPawW1rw9zzWXNGH+43D0rPjHDagBQXDHcuLCwxKqb3vzmN4ryG3WRBavyqvSMPa9Tb0faGisDHelg4xPKd/b2qaMzHbSIdUP33egGKKT5t9AshH6sKQVpHU8LDXb67vkR8e6h34FAoGAf21Aea9/+3FavddWC/5j0fvESN2U58X0xf4R/FZLa5QsT/iCAo4QqaeYZvF6csWR6lu0zJB88gA+4s6G6xP1JERL3LbE2pHjDe0eNOIsWSzsINICQQ2s3Gm5mh75+/8dfAsRiAPi9nS7FJ74Tcryb4+txeZKiBZgLnEFeRLOB3U=";
|
||||
String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsP/3AQ6DbZbQhFafYUdRS8F6jSXJzYfF3N14L48Jo+xlGp1FW8uq2bu8izP9qcuFxui2CzuQflo0BM+XmSmRt6KkmyGSvGmCdf4gC/doTT7xtMaQu72Mvezr69VC0Lp5iJeLVHzV5/BMFdgfGee5HnAUU5bn4Ytlqw14kCxgeLitZltvHtirq7vVCXlWyikbdtmV0HgmzaWbrC+jVyb/nk9oH8PpV5juJmhwEuiReEdKPKMdPoeJK3sZ9dHsOx+Bm3LkEY075fPvpHDtJFaLi/k7fFY+0oQxsX92qRL9kViOAhMonvFFKZFK06vxuPUtuZelGrzGttiOjVJRRGIiaQIDAQAB";
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
alipayConfig.setAppId("2021004144652242");
|
||||
alipayConfig.setPrivateKey(privateKey);
|
||||
alipayConfig.setFormat("json");
|
||||
alipayConfig.setAlipayPublicKey(alipayPublicKey);
|
||||
alipayConfig.setCharset("UTF-8");
|
||||
alipayConfig.setSignType("RSA2");
|
||||
return alipayConfig;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.domain.Appointments;
|
||||
import com.cj.jiaqingjiayi.model.request.appointments.AppointmentsAddRequest;
|
||||
import com.cj.jiaqingjiayi.service.AppointmentsService;
|
||||
import com.cj.jiaqingjiayi.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "预约接口")
|
||||
@RestController
|
||||
@RequestMapping("/appointments")
|
||||
public class AppointmentsController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private AppointmentsService appointmentsService;
|
||||
|
||||
@ApiOperation(value = "添加预约")
|
||||
@PostMapping("/add")
|
||||
public BaseResponse<Long> addAppointments(@RequestBody AppointmentsAddRequest appointmentsAddRequest, HttpServletRequest request){
|
||||
//校验是否登录
|
||||
Long loginUserId = userService.isLogin(request);
|
||||
ThrowUtils.throwIf(appointmentsAddRequest== null, ErrorCode.NULL_ERROR);
|
||||
|
||||
Appointments appointments = new Appointments();
|
||||
BeanUtils.copyProperties(appointmentsAddRequest, appointments);
|
||||
appointments.setUserId(loginUserId);
|
||||
//校验是否输入必要的数据
|
||||
appointmentsService.valid(appointments);
|
||||
|
||||
//返回预约号
|
||||
Long id = appointmentsService.addAppointments(appointments);
|
||||
ThrowUtils.throwIf(id < 0, ErrorCode.PARAMS_ERROR, "预约失败");
|
||||
|
||||
return ResultUtils.success(id, "预约成功");
|
||||
}
|
||||
}
|
|
@ -204,8 +204,10 @@ public class ManicuristController {
|
|||
*/
|
||||
@ApiOperation(value = "用户查询全部美甲师")
|
||||
@GetMapping("/userQueryAll")
|
||||
public BaseResponse<List<ManicuristVO>> UserQueryAllManicurist(int businessId){
|
||||
public BaseResponse<List<ManicuristVO>> UserQueryAllManicurist(@RequestBody UserManicuristQueryRequest userManicuristQueryRequest){
|
||||
ThrowUtils.throwIf(userManicuristQueryRequest == null, ErrorCode.NULL_ERROR);
|
||||
|
||||
Integer businessId = userManicuristQueryRequest.getBusinessId();
|
||||
QueryWrapper<Manicurist> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("businessId", businessId);
|
||||
List<Manicurist> manicuristList = manicuristService.list(queryWrapper);
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package com.cj.jiaqingjiayi.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cj.jiaqingjiayi.common.BaseResponse;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.common.ResultUtils;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.model.domain.Commodities;
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
import com.cj.jiaqingjiayi.model.domain.User;
|
||||
import com.cj.jiaqingjiayi.model.request.order.OrderAddRequest;
|
||||
import com.cj.jiaqingjiayi.model.request.order.OrderItemsAddRequest;
|
||||
import com.cj.jiaqingjiayi.service.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单相关接口
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "订单接口")
|
||||
@RequestMapping("/orders")
|
||||
public class OrdersController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private OrdersService ordersService;
|
||||
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
@Resource
|
||||
private OrderItemsService orderItemsService;
|
||||
|
||||
@Resource
|
||||
private CommoditiesService commoditiesService;
|
||||
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @return 订单id
|
||||
*/
|
||||
@ApiOperation(value = "订单创建接口")
|
||||
@PostMapping("/add")
|
||||
public BaseResponse<Long> addOrders(@RequestBody OrderAddRequest orderAddRequest, HttpServletRequest request) {
|
||||
if (orderAddRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
// 提取订单
|
||||
Orders orders = new Orders();
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
BeanUtils.copyProperties(orderAddRequest, orders);
|
||||
orders.setUserId(loginUser.getId());
|
||||
ordersService.validOrder(orders);
|
||||
// 提取订单详情
|
||||
List<OrderItemsAddRequest> detailAddRequest = orderAddRequest.getOrderItemsAddRequest();
|
||||
List<OrderItems> orderItemsList = detailAddRequest.stream().map(item -> {
|
||||
OrderItems orderItems = new OrderItems();
|
||||
BeanUtils.copyProperties(item, orderItems);
|
||||
orderItemsService.validOrderItems(orderItems);
|
||||
Long commoditiesId = orderItems.getCommoditiesId();
|
||||
// 根据菜品设置价格
|
||||
Commodities commodities = commoditiesService.getById(commoditiesId);
|
||||
BigDecimal commoditiesPrice = BigDecimal.valueOf(commodities.getCommoditiesPrice());
|
||||
orderItems.setPrice(commoditiesPrice);
|
||||
double subtotal = commodities.getCommoditiesPrice() * orderItems.getQuantity();
|
||||
orderItems.setSubtotal(BigDecimal.valueOf(subtotal));
|
||||
return orderItems;
|
||||
}).toList();
|
||||
// 创建订单
|
||||
long orderId = ordersService.addOrder(orders, orderItemsList);
|
||||
return ResultUtils.success(orderId, "订单创建成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.Appointments;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【appointments(预约表)】的数据库操作Mapper
|
||||
* @createDate 2024-11-05 19:07:40
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.Appointments
|
||||
*/
|
||||
public interface AppointmentsMapper extends BaseMapper<Appointments> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【order_items(详细订单表)】的数据库操作Mapper
|
||||
* @createDate 2024-11-10 14:25:15
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.OrderItems
|
||||
*/
|
||||
public interface OrderItemsMapper extends BaseMapper<OrderItems> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.mapper;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【orders(订单表)】的数据库操作Mapper
|
||||
* @createDate 2024-11-10 14:22:10
|
||||
* @Entity com.cj.jiaqingjiayi.model.domain.Orders
|
||||
*/
|
||||
public interface OrdersMapper extends BaseMapper<Orders> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package com.cj.jiaqingjiayi.model.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 预约表
|
||||
* @TableName appointments
|
||||
*/
|
||||
@TableName(value ="appointments")
|
||||
@Data
|
||||
public class Appointments implements Serializable {
|
||||
/**
|
||||
* 预约ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID(关联用户表)
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 商家ID(关联商家表)
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 商家名
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 美甲师ID, 如果为空到店分配
|
||||
*/
|
||||
private Long manicuristId;
|
||||
|
||||
/**
|
||||
* 美甲师名
|
||||
*/
|
||||
private String manicuristName;
|
||||
|
||||
/**
|
||||
* 预约时间
|
||||
*/
|
||||
private Date appointmentTime;
|
||||
|
||||
/**
|
||||
* 服务方式(0 - 线上, 1 - 到店)
|
||||
*/
|
||||
private Integer serviceMode;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 预约状态(0 - 已确认, 1 - 已完成, 2 - 已取消)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
/**
|
||||
*订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -91,6 +91,11 @@ public class Manicurist implements Serializable {
|
|||
*/
|
||||
private String manicuristAvatar;
|
||||
|
||||
/**
|
||||
* 美甲师状态
|
||||
*/
|
||||
private Integer manStatus;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.cj.jiaqingjiayi.model.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 详细订单表
|
||||
* @TableName order_items
|
||||
*/
|
||||
@TableName(value ="order_items")
|
||||
@Data
|
||||
public class OrderItems implements Serializable {
|
||||
/**
|
||||
* 详细订单ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单ID(关联订单表)
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 商品ID(美甲款式)
|
||||
*/
|
||||
private Long commoditiesId;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 商品单价
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 小计(单价 * 数量)
|
||||
*/
|
||||
private BigDecimal subtotal;
|
||||
|
||||
/**
|
||||
* 规格属性列表
|
||||
*/
|
||||
private String attributeNames;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.cj.jiaqingjiayi.model.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单表
|
||||
* @TableName orders
|
||||
*/
|
||||
@TableName(value ="orders")
|
||||
@Data
|
||||
public class Orders implements Serializable {
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String orderNumber;
|
||||
|
||||
/**
|
||||
* 用户ID(关联用户表)
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 用户姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 预约ID(关联预约表)
|
||||
*/
|
||||
private Long appointmentId;
|
||||
|
||||
/**
|
||||
* 订单总金额
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
/**
|
||||
* 支付方式:0微信支付
|
||||
*/
|
||||
private Integer payMethod;
|
||||
|
||||
/**
|
||||
* 支付状态(0 - 未支付, 1 - 已支付, 2 - 退款中, 3 - 已退款)
|
||||
*/
|
||||
private Integer paymentStatus;
|
||||
|
||||
/**
|
||||
* 抢单状态(0 - 未抢单, 1 - 已抢单)
|
||||
*/
|
||||
private Integer claimStatus;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.cj.jiaqingjiayi.model.request.appointments;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.awt.image.SampleModel;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class AppointmentsAddRequest implements Serializable {
|
||||
/**
|
||||
* 预约ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID(关联用户表)
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 商家ID(关联商家表)
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 商家名
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 美甲师ID, 如果为空到店分配
|
||||
*/
|
||||
private Long manicuristId;
|
||||
|
||||
/**
|
||||
* 美甲师名
|
||||
*/
|
||||
private String manicuristName;
|
||||
/**
|
||||
* 预约时间
|
||||
*/
|
||||
private Date appointmentTime;
|
||||
|
||||
/**
|
||||
* 服务方式(0 - 线上, 1 - 到店)
|
||||
*/
|
||||
private Integer serviceMode;
|
||||
|
||||
/**
|
||||
* 支付方式:0微信支付
|
||||
*/
|
||||
private Integer payMethod;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.cj.jiaqingjiayi.model.request.manicurist;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class UserManicuristQueryRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Integer businessId;
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.cj.jiaqingjiayi.model.request.order;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单创建请求
|
||||
*/
|
||||
@Data
|
||||
public class OrderAddRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 订单实际总价
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
*/
|
||||
private Integer payMethod;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*/
|
||||
private List<OrderItemsAddRequest> orderItemsAddRequest;
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.cj.jiaqingjiayi.model.request.order;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 订单详情创建请求
|
||||
*/
|
||||
@Data
|
||||
public class OrderItemsAddRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 关联的商品id
|
||||
*/
|
||||
private Long commoditiesId;
|
||||
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 规格属性列表
|
||||
*/
|
||||
private String attributeNames;
|
||||
|
||||
@Serial
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
import com.cj.jiaqingjiayi.model.domain.Appointments;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【appointments(预约表)】的数据库操作Service
|
||||
* @createDate 2024-11-05 19:07:40
|
||||
*/
|
||||
public interface AppointmentsService extends IService<Appointments> {
|
||||
|
||||
//校验
|
||||
void valid(Appointments appointments);
|
||||
|
||||
//预约
|
||||
Long addAppointments(Appointments appointments);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【order_items(详细订单表)】的数据库操作Service
|
||||
* @createDate 2024-11-10 14:25:15
|
||||
*/
|
||||
public interface OrderItemsService extends IService<OrderItems> {
|
||||
|
||||
/**
|
||||
* 校验订单商品
|
||||
*/
|
||||
void validOrderItems(OrderItems orderItems);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.cj.jiaqingjiayi.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【orders(订单表)】的数据库操作Service
|
||||
* @createDate 2024-11-10 14:22:10
|
||||
*/
|
||||
public interface OrdersService extends IService<Orders> {
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @return 订单id
|
||||
*/
|
||||
long addOrder(Orders orders, List<OrderItems> orderItemsList);
|
||||
|
||||
/**
|
||||
* 校验订单
|
||||
*/
|
||||
void validOrder(Orders orders);
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.model.domain.Appointments;
|
||||
import com.cj.jiaqingjiayi.model.domain.Business;
|
||||
import com.cj.jiaqingjiayi.model.domain.Manicurist;
|
||||
import com.cj.jiaqingjiayi.service.AppointmentsService;
|
||||
import com.cj.jiaqingjiayi.mapper.AppointmentsMapper;
|
||||
import com.cj.jiaqingjiayi.service.BusinessService;
|
||||
import com.cj.jiaqingjiayi.service.ManicuristService;
|
||||
import com.cj.jiaqingjiayi.utils.RegexUtils;
|
||||
import javassist.expr.NewArray;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【appointments(预约表)】的数据库操作Service实现
|
||||
* @createDate 2024-11-05 19:07:40
|
||||
*/
|
||||
@Service
|
||||
public class AppointmentsServiceImpl extends ServiceImpl<AppointmentsMapper, Appointments>
|
||||
implements AppointmentsService{
|
||||
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
@Resource
|
||||
private ManicuristService manicuristService;
|
||||
|
||||
@Override
|
||||
public void valid(Appointments appointments) {
|
||||
String userName = appointments.getUserName();
|
||||
String phone = appointments.getPhone();
|
||||
Date appointmentTime = appointments.getAppointmentTime();
|
||||
|
||||
if (StringUtils.isAnyBlank(userName, phone)){
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "信息不全");
|
||||
}
|
||||
|
||||
if (appointmentTime == null){
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "信息不全");
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(phone)){
|
||||
boolean phoneInvalid = RegexUtils.isPhoneInvalid(phone);
|
||||
ThrowUtils.throwIf(phoneInvalid, ErrorCode.PARAMS_ERROR, "手机号格式错误");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Long addAppointments(Appointments appointments) {
|
||||
ThrowUtils.throwIf(appointments == null, ErrorCode.NULL_ERROR);
|
||||
|
||||
String businessName = appointments.getBusinessName();
|
||||
String manicuristName = appointments.getManicuristName();
|
||||
|
||||
//拿到美甲师的id(是不是麻烦了呢?)
|
||||
QueryWrapper<Manicurist> manicuristQueryWrapper = new QueryWrapper<>();
|
||||
manicuristQueryWrapper.eq("manicuristName", manicuristName);
|
||||
Manicurist manicurist = manicuristService.getOne(manicuristQueryWrapper);
|
||||
if (manicurist != null){
|
||||
Long manicuristId = manicurist.getId();
|
||||
appointments.setManicuristId(manicuristId);
|
||||
}
|
||||
|
||||
//拿到商家的id
|
||||
QueryWrapper<Business> businessQueryWrapper = new QueryWrapper<>();
|
||||
businessQueryWrapper.eq("businessName", businessName);
|
||||
Business business = businessService.getOne(businessQueryWrapper);
|
||||
Long businessId = business.getId();
|
||||
|
||||
//设置给预约表
|
||||
appointments.setBusinessId(businessId);
|
||||
|
||||
boolean save = this.save(appointments);
|
||||
|
||||
ThrowUtils.throwIf(!save, ErrorCode.PARAMS_ERROR);
|
||||
|
||||
return appointments.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.exception.ThrowUtils;
|
||||
import com.cj.jiaqingjiayi.mapper.OrderItemsMapper;
|
||||
import com.cj.jiaqingjiayi.model.domain.Commodities;
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.cj.jiaqingjiayi.service.CommoditiesService;
|
||||
import com.cj.jiaqingjiayi.service.OrderItemsService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【order_items(详细订单表)】的数据库操作Service实现
|
||||
* @createDate 2024-11-10 14:25:15
|
||||
*/
|
||||
@Service
|
||||
public class OrderItemsServiceImpl extends ServiceImpl<OrderItemsMapper, OrderItems>
|
||||
implements OrderItemsService {
|
||||
|
||||
@Resource
|
||||
private CommoditiesService commoditiesService;
|
||||
|
||||
@Override
|
||||
public void validOrderItems(OrderItems orderItems) {
|
||||
Long commoditiesId = orderItems.getCommoditiesId();
|
||||
Integer quantity = orderItems.getQuantity();
|
||||
BigDecimal price = orderItems.getPrice();
|
||||
// 校验菜品是否存在
|
||||
Commodities commodities = commoditiesService.getById(commoditiesId);
|
||||
ThrowUtils.throwIf(commodities == null, ErrorCode.NOT_FOUND_ERROR, "商品不存在");
|
||||
// 有参数则校验
|
||||
if (ObjectUtils.allNotNull(commoditiesId, quantity, price)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "商品错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.cj.jiaqingjiayi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.cj.jiaqingjiayi.common.ErrorCode;
|
||||
import com.cj.jiaqingjiayi.exception.BusinessException;
|
||||
import com.cj.jiaqingjiayi.model.domain.OrderItems;
|
||||
import com.cj.jiaqingjiayi.model.domain.Orders;
|
||||
import com.cj.jiaqingjiayi.service.OrderItemsService;
|
||||
import com.cj.jiaqingjiayi.service.OrdersService;
|
||||
import com.cj.jiaqingjiayi.mapper.OrdersMapper;
|
||||
import com.cj.jiaqingjiayi.utils.RegexUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.naming.Name;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author 高木
|
||||
* @description 针对表【orders(订单表)】的数据库操作Service实现
|
||||
* @createDate 2024-11-10 14:22:10
|
||||
*/
|
||||
@Service
|
||||
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders>
|
||||
implements OrdersService{
|
||||
|
||||
@Resource
|
||||
private OrderItemsService orderItemsService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public long addOrder(Orders orders, List<OrderItems> orderItemsList) {
|
||||
// 获取当前时间的秒级时间戳(去掉年、月、日的前缀)
|
||||
String timePart = String.valueOf(System.currentTimeMillis() / 1000).substring(4);
|
||||
// 生成两位随机数
|
||||
String randomPart = String.format("%02d", new Random().nextInt(100));
|
||||
String orderNumber = timePart + randomPart;
|
||||
//设置订单号
|
||||
orders.setOrderNumber(orderNumber);
|
||||
|
||||
boolean saveOrder = this.save(orders);
|
||||
if (!saveOrder) {
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "创建订单失败,数据库错误");
|
||||
}
|
||||
// 创建订单商品
|
||||
for (OrderItems orderItems : orderItemsList) {
|
||||
// 绑定订单和订单详情
|
||||
orderItems.setOrderId(orders.getId());
|
||||
boolean saveItems = orderItemsService.save(orderItems);
|
||||
if (!saveItems) {
|
||||
log.error("创建订单商品失败,订单id:" + orders.getId());
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "订单商品创建失败");
|
||||
}
|
||||
}
|
||||
return orders.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validOrder(Orders orders) {
|
||||
String userName = orders.getUserName();
|
||||
String phone = orders.getPhone();
|
||||
Long userId = orders.getUserId();
|
||||
Long businessId = orders.getBusinessId();
|
||||
BigDecimal totalPrice = orders.getTotalPrice();
|
||||
Integer payMethod = orders.getPayMethod();
|
||||
if (StringUtils.isAnyBlank(userName, phone)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
if (StringUtils.isNotBlank(phone) && RegexUtils.isPhoneInvalid(phone)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "手机号格式错误");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(totalPrice) || totalPrice.floatValue() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "价格错误");
|
||||
}
|
||||
if (ObjectUtils.anyNull(userId, businessId, payMethod)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数不全");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -2,9 +2,9 @@ spring:
|
|||
application:
|
||||
name: jiaqingjiayi
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://154.8.193.216/jiaqingjiayi
|
||||
# username: jiaqingjiayi
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://154.8.193.216/jqjy
|
||||
# username: jqjy
|
||||
# password: 123456
|
||||
url: jdbc:mysql://localhost:3306/jqjy
|
||||
username: root
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.AppointmentsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.Appointments">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="userName" column="userName" jdbcType="VARCHAR"/>
|
||||
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
||||
<result property="businessId" column="businessId" jdbcType="BIGINT"/>
|
||||
<result property="manicuristId" column="manicuristId" jdbcType="BIGINT"/>
|
||||
<result property="appointmentTime" column="appointmentTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="serviceMode" column="serviceMode" jdbcType="TINYINT"/>
|
||||
<result property="notes" column="notes" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="TINYINT"/>
|
||||
<result property="orderId" column="orderId" jdbcType="BIGINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="isDelete" column="isDelete" jdbcType="TINYINT"/>
|
||||
<result property="businessName" column="businessName" jdbcType="VARCHAR"/>
|
||||
<result property="manicuristName" column="manicuristName" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,userId,userName,
|
||||
phone,businessId,manicuristId,
|
||||
appointmentTime,serviceMode,
|
||||
notes,status,createTime,
|
||||
updateTime,isDelete,businessName,
|
||||
manicuristName,orderId
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.OrderItemsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.OrderItems">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="orderId" column="orderId" jdbcType="BIGINT"/>
|
||||
<result property="commoditiesId" column="commoditiesId" jdbcType="BIGINT"/>
|
||||
<result property="quantity" column="quantity" jdbcType="INTEGER"/>
|
||||
<result property="price" column="price" jdbcType="DECIMAL"/>
|
||||
<result property="subtotal" column="subtotal" jdbcType="DECIMAL"/>
|
||||
<result property="attributeNames" column="attributeNames" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="isDelete" column="isDelete" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,orderId,commoditiesId,
|
||||
quantity,price,subtotal,
|
||||
attributeNames,createTime,updateTime,
|
||||
isDelete
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cj.jiaqingjiayi.mapper.OrdersMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cj.jiaqingjiayi.model.domain.Orders">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="orderNumber" column="orderNumber" jdbcType="VARCHAR"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="businessId" column="businessId" jdbcType="BIGINT"/>
|
||||
<result property="userName" column="userName" jdbcType="VARCHAR"/>
|
||||
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
||||
<result property="payMethod" column="payMethod" jdbcType="TINYINT"/>
|
||||
<result property="appointmentId" column="appointmentId" jdbcType="BIGINT"/>
|
||||
<result property="totalPrice" column="totalPrice" jdbcType="DECIMAL"/>
|
||||
<result property="paymentStatus" column="paymentStatus" jdbcType="TINYINT"/>
|
||||
<result property="claimStatus" column="claimStatus" jdbcType="TINYINT"/>
|
||||
<result property="notes" column="notes" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="isDelete" column="isDelete" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,orderNumber,userId,
|
||||
businessId,userName,phone,
|
||||
appointmentId,totalPrice,paymentStatus,
|
||||
claimStatus,notes,createTime,
|
||||
updateTime,isDelete,payMethod
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user