Compare commits
14 Commits
e3966a999a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d11ada62c | |||
| 333fa769cc | |||
| f68ed79b7f | |||
| 28cb22928f | |||
| 79587613d8 | |||
| 7bfbd10b9d | |||
| 96c6308c52 | |||
| cf18e8bd82 | |||
| 4734a67b59 | |||
| ea8347d6b9 | |||
| 762b45a207 | |||
| 0b77bc7d70 | |||
| 7747190fd9 | |||
| aac5b7c677 |
@@ -21,6 +21,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.cert.X509Certificate;
|
||||
@@ -188,7 +189,7 @@ public class WeChatPayUtil {
|
||||
byte[] message = signMessage.getBytes();
|
||||
|
||||
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||
signature.initSign(PemUtil.loadPrivateKey(new FileInputStream(new File(weChatProperties.getPrivateKeyFilePath()))));
|
||||
signature.initSign(PemUtil.loadPrivateKey(Files.newInputStream(new File(weChatProperties.getPrivateKeyFilePath()).toPath())));
|
||||
signature.update(message);
|
||||
String packageSign = Base64.getEncoder().encodeToString(signature.sign());
|
||||
|
||||
|
||||
@@ -115,6 +115,11 @@
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>6.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.sky;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
@@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement //开启注解方式的事务管理
|
||||
@EnableCaching
|
||||
@Slf4j
|
||||
public class SkyApplication {
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class RedisConfiguration {
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
//设置序列化器
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||
// redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.*;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderStatisticsVO;
|
||||
import com.sky.vo.OrderVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("adminOrderController")
|
||||
@RequestMapping("/admin/order")
|
||||
@Api(tags = "Order-Controller")
|
||||
@Slf4j
|
||||
public class OrderController {
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@GetMapping("/conditionSearch")
|
||||
public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
|
||||
PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
@GetMapping("/statistics")
|
||||
public Result<OrderStatisticsVO> statistics() {
|
||||
log.info("order overview");
|
||||
OrderStatisticsVO orderStatisticsVO = orderService.statistics();
|
||||
return Result.success(orderStatisticsVO);
|
||||
}
|
||||
|
||||
@GetMapping("/details/{id}")
|
||||
public Result<OrderVO> details(@PathVariable Long id) {
|
||||
log.info("check order details: {}",id);
|
||||
OrderVO orderVO = orderService.details(id);
|
||||
return Result.success(orderVO);
|
||||
}
|
||||
|
||||
@PutMapping("/confirm")
|
||||
public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
|
||||
log.info("order confirm: {}",ordersConfirmDTO);
|
||||
orderService.confirm(ordersConfirmDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/rejection")
|
||||
public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
|
||||
log.info("order rejection: {}",ordersRejectionDTO);
|
||||
orderService.rejection(ordersRejectionDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/complete/{id}")
|
||||
public Result complete(@PathVariable Long id){
|
||||
log.info("complete order: {}",id);
|
||||
orderService.complete(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/cancel")
|
||||
public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
|
||||
log.info("order cancel: {}",ordersCancelDTO);
|
||||
orderService.cancelFromAdmin(ordersCancelDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/delivery/{id}")
|
||||
public Result delivery(@PathVariable Long id){
|
||||
log.info("order delivery: {}",id);
|
||||
orderService.delivery(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,6 +44,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
|
||||
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("新增套餐: {}",setmealDTO);
|
||||
setmealService.insert(setmealDTO);
|
||||
@@ -56,6 +58,7 @@ public class SetmealController {
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("批量删除套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result delete(@RequestParam List<Long> ids){
|
||||
log.info("批量删除套餐: {}",ids);
|
||||
setmealService.deleteBatch(ids);
|
||||
@@ -82,6 +85,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("修改套餐: {}",setmealDTO);
|
||||
setmealService.updateWithSetmealDishes(setmealDTO);
|
||||
@@ -96,6 +100,7 @@ public class SetmealController {
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("套餐起售停售")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
||||
setmealService.startOrStop(status,id);
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.sky.controller.notify;
|
||||
|
||||
import com.alibaba.druid.support.json.JSONUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sky.properties.WeChatProperties;
|
||||
import com.sky.service.OrderService;
|
||||
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 支付回调相关接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/notify")
|
||||
@Slf4j
|
||||
public class PayNotifyController {
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
@Autowired
|
||||
private WeChatProperties weChatProperties;
|
||||
|
||||
/**
|
||||
* 支付成功回调
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@RequestMapping("/paySuccess")
|
||||
public void paySuccessNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
//读取数据
|
||||
String body = readData(request);
|
||||
log.info("支付成功回调:{}", body);
|
||||
|
||||
//数据解密
|
||||
String plainText = decryptData(body);
|
||||
log.info("解密后的文本:{}", plainText);
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(plainText);
|
||||
String outTradeNo = jsonObject.getString("out_trade_no");//商户平台订单号
|
||||
String transactionId = jsonObject.getString("transaction_id");//微信支付交易号
|
||||
|
||||
log.info("商户平台订单号:{}", outTradeNo);
|
||||
log.info("微信支付交易号:{}", transactionId);
|
||||
|
||||
//业务处理,修改订单状态、来单提醒
|
||||
orderService.paySuccess(outTradeNo);
|
||||
|
||||
//给微信响应
|
||||
responseToWeixin(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private String readData(HttpServletRequest request) throws Exception {
|
||||
BufferedReader reader = request.getReader();
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (result.length() > 0) {
|
||||
result.append("\n");
|
||||
}
|
||||
result.append(line);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据解密
|
||||
*
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private String decryptData(String body) throws Exception {
|
||||
JSONObject resultObject = JSON.parseObject(body);
|
||||
JSONObject resource = resultObject.getJSONObject("resource");
|
||||
String ciphertext = resource.getString("ciphertext");
|
||||
String nonce = resource.getString("nonce");
|
||||
String associatedData = resource.getString("associated_data");
|
||||
|
||||
AesUtil aesUtil = new AesUtil(weChatProperties.getApiV3Key().getBytes(StandardCharsets.UTF_8));
|
||||
//密文解密
|
||||
String plainText = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8),
|
||||
nonce.getBytes(StandardCharsets.UTF_8),
|
||||
ciphertext);
|
||||
|
||||
return plainText;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给微信响应
|
||||
* @param response
|
||||
*/
|
||||
private void responseToWeixin(HttpServletResponse response) throws Exception{
|
||||
response.setStatus(200);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
response.setHeader("Content-type", ContentType.APPLICATION_JSON.toString());
|
||||
response.getOutputStream().write(JSONUtils.toJSONString(map).getBytes(StandardCharsets.UTF_8));
|
||||
response.flushBuffer();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.AddressBookService;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/addressBook")
|
||||
@Slf4j
|
||||
@Api(tags = "AddressBook-Controller")
|
||||
public class AddressBookController {
|
||||
|
||||
@Autowired
|
||||
private AddressBookService addressBookService;
|
||||
|
||||
/**
|
||||
* add a new address
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public Result add(@RequestBody AddressBook addressBook){
|
||||
log.info("add new address book");
|
||||
addressBookService.addAddressBook(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* list address of current user
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<List<AddressBook>> list(){
|
||||
log.info("list address of current user");
|
||||
List<AddressBook> list = addressBookService.listAddress();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* list default address of current user
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/default")
|
||||
public Result<AddressBook> listDefault(){
|
||||
log.info("list default address of current user");
|
||||
AddressBook addressBook = addressBookService.listDefault();
|
||||
return Result.success(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* list by addressId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<AddressBook> listByAddressId(@PathVariable Long id){
|
||||
log.info("list address by id: {}", id);
|
||||
AddressBook addressBook = addressBookService.listByAddressId(id);
|
||||
return Result.success(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* update address
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
public Result updateAddress(@RequestBody AddressBook addressBook){
|
||||
log.info("update address");
|
||||
addressBookService.updateAddress(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public Result deleteAddress(Long id){
|
||||
log.info("delete address");
|
||||
addressBookService.deleteAddress(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/default")
|
||||
public Result setDefault(@RequestBody AddressBook addressBook){
|
||||
log.info("set default address");
|
||||
addressBookService.setDefault(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.sky.entity.Category;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -13,15 +14,16 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RestController("UserCategoeyController")
|
||||
@RequestMapping("/user/category")
|
||||
@Api(tags = "Category")
|
||||
@Slf4j
|
||||
public class UserCategoryController {
|
||||
public class CategoryController {
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("category list")
|
||||
public Result<List<Category>> list(Integer type){
|
||||
log.info("user category list: {}",type);
|
||||
List<Category> list = categoryService.list(type);
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController("UserDishController")
|
||||
@RequestMapping("/user/dish")
|
||||
@Api(tags = "UserDish")
|
||||
@Slf4j
|
||||
public class DishController {
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<List<DishVO>> list(Long categoryId) {
|
||||
log.info("select dishes by categoryId {}", categoryId);
|
||||
return Result.success(dishService.getDishVoByCategoryId(categoryId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.dto.OrdersPaymentDTO;
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderPaymentVO;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
import com.sky.vo.OrderVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController("userOrderController")
|
||||
@RequestMapping("/user/order")
|
||||
@Slf4j
|
||||
@Api(tags = "Order-Controller")
|
||||
public class OrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@PostMapping("/submit")
|
||||
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
|
||||
log.info("order submit: {}", ordersSubmitDTO);
|
||||
OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
|
||||
return Result.success(orderSubmitVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
*
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/payment")
|
||||
@ApiOperation("订单支付")
|
||||
public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||
log.info("订单支付:{}", ordersPaymentDTO);
|
||||
OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
|
||||
log.info("生成预支付交易单:{}", orderPaymentVO);
|
||||
return Result.success(orderPaymentVO);
|
||||
}
|
||||
|
||||
@GetMapping("/historyOrders")
|
||||
public Result<PageResult> historyOrders(Integer page, Integer pageSize, Integer status) {
|
||||
log.info("查询历史订单");
|
||||
PageResult pageResult = orderService.getHistoryOrders(page, pageSize, status);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
@GetMapping("/orderDetail/{id}")
|
||||
public Result<OrderVO> orderDetail(@PathVariable Long id) {
|
||||
log.info("check order detail: {}", id);
|
||||
OrderVO orderVO = orderService.getOrderDetailById(id);
|
||||
return Result.success(orderVO);
|
||||
}
|
||||
|
||||
@PutMapping("/cancel/{id}")
|
||||
public Result cancel(@PathVariable Long id) {
|
||||
log.info("cancel order: {}", id);
|
||||
orderService.cancelByUser(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/repetition/{id}")
|
||||
public Result repetition(@PathVariable Long id) {
|
||||
log.info("repetition order: {}", id);
|
||||
orderService.repetition(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.service.ShoppingCartService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController("UserSetmealController")
|
||||
@RequestMapping("/user/setmeal")
|
||||
@Api(tags = "UserSetmeal")
|
||||
@Slf4j
|
||||
public class SetmealController {
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("select setmeal by categoryId")
|
||||
@Cacheable(cacheNames = "setmealCache",key = "#categoryId")
|
||||
public Result<List<Setmeal>> list(Integer categoryId){
|
||||
log.info("select setmeal by categoryId :{}", categoryId);
|
||||
List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(categoryId);
|
||||
return Result.success(setmealList);
|
||||
}
|
||||
|
||||
@GetMapping("/dish/{id}")
|
||||
@ApiOperation("select dishes by setmealId")
|
||||
public Result<List<DishItemVO>> getDishBySetmealId(@PathVariable Long id){
|
||||
log.info("select dishes by setmealId :{}", id);
|
||||
return Result.success(setmealService.getDishBySetmealId(id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.ShoppingCartService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/shoppingCart")
|
||||
@Slf4j
|
||||
@Api(tags = "ShoppingCart-Controller")
|
||||
public class ShoppingCartController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCartService shoppingCartService;
|
||||
|
||||
/**
|
||||
* Adds an item into the shopping cart.
|
||||
*
|
||||
* @param shoppingCartDTO The data transfer object encapsulating the details of the item to be added.
|
||||
* Includes 'dishId' for individual dishes, 'setmealId' for set meals, and 'dishFlavor' to specify dish flavors if applicable.
|
||||
* @return A {@link Result} indicating the outcome of the operation, with a success code and no specific data content.
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("add into shopping cart")
|
||||
public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||
log.info("add into shopping cart, details: {}",shoppingCartDTO);
|
||||
shoppingCartService.addIntoShoppingCart(shoppingCartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* list the shopping cart of current user
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("list shopping cart")
|
||||
public Result<List<ShoppingCart>> list(){
|
||||
log.info("list shopping cart");
|
||||
List<ShoppingCart> list = shoppingCartService.listShoppingCart();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* clean shopping cart
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/clean")
|
||||
@ApiOperation("clean the shopping cart")
|
||||
public Result clean(){
|
||||
log.info("clean shopping cart");
|
||||
shoppingCartService.cleanShoppingCart();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* subtract an item from the shopping cart
|
||||
* @param shoppingCartDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/sub")
|
||||
@ApiOperation("subtract an item from the shopping cart")
|
||||
public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||
shoppingCartService.subtractFromShoppingCart(shoppingCartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
|
||||
public class UserSetmealController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.AddressBook;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AddressBookMapper {
|
||||
|
||||
@Insert("insert into sky_take_out.address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
|
||||
"values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
|
||||
void insert(AddressBook addressBook);
|
||||
|
||||
List<AddressBook> list(AddressBook addressBook);
|
||||
|
||||
void update(AddressBook addressBook);
|
||||
|
||||
@Delete("delete from sky_take_out.address_book where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
|
||||
@Update("update sky_take_out.address_book set is_default = 0 where user_id = #{userId}")
|
||||
void updateNotDefault(Long userId);
|
||||
|
||||
@Update("update sky_take_out.address_book set is_default = 1 where id = #{id}")
|
||||
void updateDefault(Long id);
|
||||
|
||||
@Select("select * from sky_take_out.address_book where id = #{addressBookId}")
|
||||
AddressBook getById(Long addressBookId);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -66,8 +68,10 @@ public interface DishMapper {
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from dish where category_id = #{categoryId}")
|
||||
@Select("select * from dish where category_id = #{categoryId} and status = 1")
|
||||
List<Dish> selectByCategoryId(Long categoryId);
|
||||
|
||||
List<Dish> selectByDishIdsAndStatusDisable(List<Long> dishIds);
|
||||
|
||||
List<DishItemVO> selectDishBySetmealId(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.OrderDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderDetailMapper {
|
||||
|
||||
/**
|
||||
* insert order details into table order_detail
|
||||
* @param orderDetails
|
||||
*/
|
||||
void insertBatch(List<OrderDetail> orderDetails);
|
||||
|
||||
List<OrderDetail> getByOrderId(Long orderId);
|
||||
}
|
||||
43
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
43
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.dto.OrdersPageQueryDTO;
|
||||
import com.sky.entity.Orders;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
|
||||
void insert(Orders orders);
|
||||
|
||||
/**
|
||||
* 根据订单号查询订单
|
||||
*
|
||||
* @param orderNumber
|
||||
*/
|
||||
@Select("select * from orders where number = #{orderNumber}")
|
||||
Orders getByNumber(String orderNumber);
|
||||
|
||||
/**
|
||||
* 修改订单信息
|
||||
*
|
||||
* @param orders
|
||||
*/
|
||||
void update(Orders orders);
|
||||
|
||||
@Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
|
||||
void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
|
||||
|
||||
Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||
|
||||
@Select("select * from orders where id = #{id}")
|
||||
Orders getById(Long id);
|
||||
|
||||
@Select("select count(*) from orders where status = #{status}")
|
||||
int countStatus(Integer status);
|
||||
}
|
||||
@@ -33,4 +33,7 @@ public interface SetmealMapper {
|
||||
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Setmeal setmeal);
|
||||
|
||||
@Select("select * from setmeal where category_id = #{categoryId}")
|
||||
List<Setmeal> selectByCategoryId(Integer categoryId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ShoppingCartMapper {
|
||||
|
||||
/**
|
||||
* Retrieves a list of shopping carts based on a given ShoppingCart instance.
|
||||
* This method is typically used to fetch carts matching specific criteria
|
||||
* encapsulated within the provided ShoppingCart object.
|
||||
*
|
||||
* @param shoppingCart An instance of ShoppingCart containing criteria
|
||||
* for the search. The fields within this object may be
|
||||
* used to filter or customize the retrieval of shopping carts.
|
||||
* @return A list of ShoppingCart instances that match the criteria specified
|
||||
* in the input ShoppingCart object. If no carts match, an empty list is returned.
|
||||
*/
|
||||
List<ShoppingCart> list(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* update the item number by item's id
|
||||
* @param shoppingCart
|
||||
*/
|
||||
@Update("update sky_take_out.shopping_cart set number = #{number} where id = #{id}")
|
||||
void updateNumberById(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* insert a new item into the shopping cart
|
||||
* @param shoppingCart
|
||||
*/
|
||||
@Insert("insert into sky_take_out.shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
|
||||
"values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
|
||||
void insert(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* clean shopping cart
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
||||
void clean(Long userId);
|
||||
|
||||
/**
|
||||
* delete the item that number is 0 from the shopping cart
|
||||
* @param shoppingCart
|
||||
*/
|
||||
void delete(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* delete shopping cart by user id
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* insert all the shopping cart data
|
||||
* @param shoppingCartList
|
||||
*/
|
||||
void insertBatch(List<ShoppingCart> shoppingCartList);
|
||||
}
|
||||
@@ -20,4 +20,7 @@ public interface UserMapper {
|
||||
* @param user
|
||||
*/
|
||||
void insert(User user);
|
||||
|
||||
@Select("select * from sky_take_out.user where id = #{userId}")
|
||||
User getById(Long userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.entity.AddressBook;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface AddressBookService {
|
||||
|
||||
/**
|
||||
* Add new address book
|
||||
* @param addressBook
|
||||
*/
|
||||
void addAddressBook(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* list address of current user
|
||||
* @return
|
||||
*/
|
||||
List<AddressBook> listAddress();
|
||||
|
||||
/**
|
||||
* show default address
|
||||
* @return
|
||||
*/
|
||||
AddressBook listDefault();
|
||||
|
||||
/**
|
||||
* list by address id
|
||||
* @param addressId
|
||||
* @return
|
||||
*/
|
||||
AddressBook listByAddressId(Long addressId);
|
||||
|
||||
/**
|
||||
* update address
|
||||
* @param addressBook
|
||||
*/
|
||||
void updateAddress(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* delete address
|
||||
*/
|
||||
void deleteAddress(Long id);
|
||||
|
||||
/**
|
||||
* set default address
|
||||
* @param addressBook
|
||||
*/
|
||||
void setDefault(AddressBook addressBook);
|
||||
}
|
||||
@@ -57,4 +57,6 @@ public interface DishService {
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
List<DishVO> getDishVoByCategoryId(Long categoryId);
|
||||
}
|
||||
|
||||
110
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
110
sky-server/src/main/java/com/sky/service/OrderService.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.*;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface OrderService {
|
||||
|
||||
/**
|
||||
* submit order
|
||||
* @param ordersSubmitDTO
|
||||
* @return
|
||||
*/
|
||||
OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO);
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception;
|
||||
|
||||
/**
|
||||
* 支付成功,修改订单状态
|
||||
* @param outTradeNo
|
||||
*/
|
||||
void paySuccess(String outTradeNo);
|
||||
|
||||
/**
|
||||
* 获取历史订单
|
||||
* (page query for user)
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status);
|
||||
|
||||
/**
|
||||
* get order detail by order id
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
OrderVO getOrderDetailById(Long id);
|
||||
|
||||
/**
|
||||
* cancel order by user
|
||||
* @param id
|
||||
*/
|
||||
void cancelByUser(Long id);
|
||||
|
||||
/**
|
||||
* repeat order by order id
|
||||
* @param id
|
||||
*/
|
||||
void repetition(Long id);
|
||||
|
||||
/**
|
||||
* page query for admin
|
||||
* @param ordersPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
|
||||
|
||||
/**
|
||||
* order overview
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
OrderStatisticsVO statistics();
|
||||
|
||||
/**
|
||||
* check order details
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
OrderVO details(Long id);
|
||||
|
||||
/**
|
||||
* confirm order
|
||||
* @param ordersConfirmDTO
|
||||
*/
|
||||
void confirm(OrdersConfirmDTO ordersConfirmDTO);
|
||||
|
||||
/**
|
||||
* reject order
|
||||
* @param ordersRejectionDTO
|
||||
*/
|
||||
void rejection(OrdersRejectionDTO ordersRejectionDTO);
|
||||
|
||||
/**
|
||||
* cancel order by admin
|
||||
* @param ordersCancelDTO
|
||||
*/
|
||||
void cancelFromAdmin(OrdersCancelDTO ordersCancelDTO);
|
||||
|
||||
/**
|
||||
* delivery order
|
||||
* @param id
|
||||
*/
|
||||
void delivery(Long id);
|
||||
|
||||
/**
|
||||
* complete order
|
||||
* @param id
|
||||
*/
|
||||
void complete(Long id);
|
||||
}
|
||||
@@ -2,7 +2,10 @@ package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -48,4 +51,8 @@ public interface SetmealService {
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
List<Setmeal> selectSetmealByCategoryId(Integer categoryId);
|
||||
|
||||
List<DishItemVO> getDishBySetmealId(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface ShoppingCartService {
|
||||
|
||||
/**
|
||||
* Adds a setmeal or dish to the shopping cart.
|
||||
*
|
||||
* @param shoppingCartDTO The data transfer object containing details of the item to be added to the shopping cart.
|
||||
* It includes dishId, setmealId, and dishFlavor necessary for identifying and customizing the item.
|
||||
*/
|
||||
void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
|
||||
/**
|
||||
* list shopping cart of current user
|
||||
* @return
|
||||
*/
|
||||
List<ShoppingCart> listShoppingCart();
|
||||
|
||||
/**
|
||||
* clean shopping cart
|
||||
*/
|
||||
void cleanShoppingCart();
|
||||
|
||||
/**
|
||||
* subtract an item from the shopping cart
|
||||
* @param shoppingCartDTO
|
||||
*/
|
||||
void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.mapper.AddressBookMapper;
|
||||
import com.sky.service.AddressBookService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AddressBookServiceImpl implements AddressBookService {
|
||||
|
||||
@Autowired
|
||||
private AddressBookMapper addressBookMapper;
|
||||
|
||||
@Override
|
||||
public void addAddressBook(AddressBook addressBook) {
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
addressBook.setUserId(userId);
|
||||
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||
addressBook.setIsDefault(0);
|
||||
addressBookMapper.insert(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* list address of current user
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AddressBook> listAddress() {
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
AddressBook addressBook = AddressBook.builder()
|
||||
.userId(userId)
|
||||
.build();
|
||||
return addressBookMapper.list(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* show default address
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AddressBook listDefault() {
|
||||
AddressBook addressBook = AddressBook.builder()
|
||||
.userId(BaseContext.getCurrentId())
|
||||
.isDefault(1)
|
||||
.build();
|
||||
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddressBook listByAddressId(Long addressId) {
|
||||
AddressBook addressBook = AddressBook.builder()
|
||||
.id(addressId)
|
||||
.build();
|
||||
List<AddressBook> list = addressBookMapper.list(addressBook);
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAddress(AddressBook addressBook) {
|
||||
addressBookMapper.update(addressBook);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAddress(Long id) {
|
||||
addressBookMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void setDefault(AddressBook addressBook) {
|
||||
//set all the address of current user not default
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
addressBookMapper.updateNotDefault(userId);
|
||||
//set current address default
|
||||
addressBookMapper.updateDefault(addressBook.getId());
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,21 @@ import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -38,6 +45,8 @@ public class DishServiceImpl implements DishService {
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 新增菜品
|
||||
@@ -64,6 +73,9 @@ public class DishServiceImpl implements DishService {
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
|
||||
//clear redis cache
|
||||
String key = "dish_"+dishDTO.getCategoryId();
|
||||
cleanCache(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,6 +121,9 @@ public class DishServiceImpl implements DishService {
|
||||
}*/
|
||||
dishMapper.deleteByIds(ids);
|
||||
dishFlavorMapper.deleteByDishIds(ids);
|
||||
|
||||
//clear all the dish cache in redis
|
||||
cleanCache("dish_*");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +171,9 @@ public class DishServiceImpl implements DishService {
|
||||
//插入新的口味数据
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
|
||||
//clear redis cache
|
||||
cleanCache("dish_*");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,5 +213,42 @@ public class DishServiceImpl implements DishService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanCache("dish_*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishVO> getDishVoByCategoryId(Long categoryId) {
|
||||
List<DishVO> dishVOList;
|
||||
|
||||
//construct key in redis: dish_{categoryId}
|
||||
String key = "dish_"+categoryId;
|
||||
|
||||
//check if dish data exists in redis
|
||||
ValueOperations valueOperations = redisTemplate.opsForValue();
|
||||
dishVOList = (List<DishVO>) valueOperations.get(key);
|
||||
|
||||
if (dishVOList != null && !dishVOList.isEmpty()) {
|
||||
//if exists,return dish data
|
||||
return dishVOList;
|
||||
}else {
|
||||
//if not exists
|
||||
List<Dish> dishes = dishMapper.selectByCategoryId(categoryId);
|
||||
dishVOList = new ArrayList<>();
|
||||
for (Dish dish : dishes) {
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(dish, dishVO);
|
||||
dishVO.setFlavors(dishFlavorMapper.getByDishId(dish.getId()));
|
||||
dishVOList.add(dishVO);
|
||||
}
|
||||
valueOperations.set(key, dishVOList);
|
||||
return dishVOList;
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanCache(String pattern) {
|
||||
//clear redis cache
|
||||
Set keys = redisTemplate.keys(pattern);
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.*;
|
||||
import com.sky.entity.*;
|
||||
import com.sky.exception.AddressBookBusinessException;
|
||||
import com.sky.exception.ShoppingCartBusinessException;
|
||||
import com.sky.mapper.*;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.utils.WeChatPayUtil;
|
||||
import com.sky.vo.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private AddressBookMapper addressBookMapper;
|
||||
@Autowired
|
||||
private ShoppingCartMapper shoppingCartMapper;
|
||||
@Autowired
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private WeChatPayUtil weChatPayUtil;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderSubmitVO submitOrder(OrdersSubmitDTO ordersSubmitDTO) {
|
||||
//handle exception situation(address book is empty, shopping cart is empty)
|
||||
AddressBook addressBook = addressBookMapper.getById(ordersSubmitDTO.getAddressBookId());
|
||||
if (addressBook == null) {
|
||||
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
|
||||
}
|
||||
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
shoppingCart.setUserId(userId);
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new ShoppingCartBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
|
||||
}
|
||||
|
||||
//insert data into orders table
|
||||
Orders orders = new Orders();
|
||||
BeanUtils.copyProperties(ordersSubmitDTO, orders);
|
||||
orders.setUserId(userId);
|
||||
orders.setOrderTime(LocalDateTime.now());
|
||||
orders.setPayStatus(Orders.UN_PAID);
|
||||
orders.setStatus(Orders.PENDING_PAYMENT);
|
||||
orders.setNumber(userId + "-" + System.currentTimeMillis());
|
||||
orders.setPhone(addressBook.getPhone());
|
||||
orders.setUserName(addressBook.getConsignee());
|
||||
orders.setConsignee(addressBook.getConsignee());
|
||||
orders.setAddress(addressBook.getDetail());
|
||||
|
||||
orderMapper.insert(orders);
|
||||
|
||||
//insert data into data_detail table
|
||||
List<OrderDetail> orderDetails = new ArrayList<>();
|
||||
for (ShoppingCart cart : list) {
|
||||
OrderDetail orderDetail = new OrderDetail();
|
||||
BeanUtils.copyProperties(cart, orderDetail);
|
||||
orderDetail.setOrderId(orders.getId());
|
||||
orderDetails.add(orderDetail);
|
||||
}
|
||||
orderDetailMapper.insertBatch(orderDetails);
|
||||
|
||||
//clear the shopping cart of current user
|
||||
shoppingCartMapper.deleteByUserId(userId);
|
||||
|
||||
//construct OrderSubmitVO
|
||||
return OrderSubmitVO.builder()
|
||||
.id(orders.getId())
|
||||
.orderTime(orders.getOrderTime())
|
||||
.orderNumber(orders.getNumber())
|
||||
.orderAmount(orders.getAmount())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
*
|
||||
* @param ordersPaymentDTO
|
||||
* @return
|
||||
*/
|
||||
public OrderPaymentVO payment(OrdersPaymentDTO ordersPaymentDTO) throws Exception {
|
||||
// 当前登录用户id
|
||||
|
||||
/*Long userId = BaseContext.getCurrentId();
|
||||
User user = userMapper.getById(userId);
|
||||
|
||||
//调用微信支付接口,生成预支付交易单
|
||||
JSONObject jsonObject = weChatPayUtil.pay(
|
||||
ordersPaymentDTO.getOrderNumber(), //商户订单号
|
||||
new BigDecimal(0.01), //支付金额,单位 元
|
||||
"苍穹外卖订单", //商品描述
|
||||
user.getOpenid() //微信用户的openid
|
||||
);
|
||||
|
||||
if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("ORDERPAID")) {
|
||||
throw new OrderBusinessException("该订单已支付");
|
||||
}*/
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code", "ORDERPAID");
|
||||
|
||||
OrderPaymentVO vo = jsonObject.toJavaObject(OrderPaymentVO.class);
|
||||
vo.setPackageStr(jsonObject.getString("package"));
|
||||
|
||||
//为替代微信支付成功后的数据库订单状态更新,多定义一个方法进行修改
|
||||
|
||||
Integer OrderPaidStatus = Orders.PAID; //支付状态,已支付
|
||||
|
||||
Integer OrderStatus = Orders.TO_BE_CONFIRMED; //订单状态,待接单
|
||||
|
||||
|
||||
//发现没有将支付时间 check_out属性赋值,所以在这里更新
|
||||
|
||||
LocalDateTime check_out_time = LocalDateTime.now();
|
||||
|
||||
|
||||
Long orderId = orderMapper.getByNumber(ordersPaymentDTO.getOrderNumber()).getId();
|
||||
orderMapper.updateStatus(OrderStatus, OrderPaidStatus, check_out_time, orderId);
|
||||
|
||||
return new OrderPaymentVO();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功,修改订单状态
|
||||
*
|
||||
* @param outTradeNo
|
||||
*/
|
||||
public void paySuccess(String outTradeNo) {
|
||||
|
||||
// 根据订单号查询订单
|
||||
Orders ordersDB = orderMapper.getByNumber(outTradeNo);
|
||||
|
||||
// 根据订单id更新订单的状态、支付方式、支付状态、结账时间
|
||||
Orders orders = Orders.builder()
|
||||
.id(ordersDB.getId())
|
||||
.status(Orders.TO_BE_CONFIRMED)
|
||||
.payStatus(Orders.PAID)
|
||||
.checkoutTime(LocalDateTime.now())
|
||||
.build();
|
||||
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult getHistoryOrders(Integer page, Integer pageSize, Integer status) {
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
PageHelper.startPage(page, pageSize);
|
||||
OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
|
||||
ordersPageQueryDTO.setUserId(userId);
|
||||
ordersPageQueryDTO.setStatus(status);
|
||||
|
||||
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||
List<OrderVO> list = new ArrayList<>();
|
||||
if (ordersPage != null && ordersPage.getTotal() > 0) {
|
||||
for (Orders order : ordersPage) {
|
||||
List<OrderDetail> orderDetails = orderDetailMapper.getByOrderId(order.getId());
|
||||
OrderVO orderVO = new OrderVO();
|
||||
orderVO.setOrderDetailList(orderDetails);
|
||||
BeanUtils.copyProperties(order, orderVO);
|
||||
list.add(orderVO);
|
||||
}
|
||||
}
|
||||
return new PageResult(list.size(), list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderVO getOrderDetailById(Long id) {
|
||||
OrderVO orderVO = new OrderVO();
|
||||
Orders orders = orderMapper.getById(id);
|
||||
BeanUtils.copyProperties(orders, orderVO);
|
||||
orderVO.setOrderDetailList(orderDetailMapper.getByOrderId(orderVO.getId()));
|
||||
return orderVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelByUser(Long id) {
|
||||
Orders orders = new Orders();
|
||||
orders.setId(id);
|
||||
orders.setStatus(Orders.CANCELLED);
|
||||
orders.setCancelTime(LocalDateTime.now());
|
||||
orders.setPayStatus(Orders.REFUND);
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repetition(Long id) {
|
||||
//get information of order detail
|
||||
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);
|
||||
//construct shopping cart
|
||||
List<ShoppingCart> shoppingCartList = new ArrayList<>();
|
||||
for (OrderDetail orderDetail : orderDetailList) {
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
shoppingCart.setName(orderDetail.getName());
|
||||
shoppingCart.setImage(orderDetail.getImage());
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
shoppingCart.setDishId(orderDetail.getDishId());
|
||||
shoppingCart.setSetmealId(orderDetail.getSetmealId());
|
||||
shoppingCart.setDishFlavor(orderDetail.getDishFlavor());
|
||||
shoppingCart.setNumber(orderDetail.getNumber());
|
||||
shoppingCart.setAmount(orderDetail.getAmount());
|
||||
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||
shoppingCartList.add(shoppingCart);
|
||||
}
|
||||
shoppingCartMapper.insertBatch(shoppingCartList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult pageQuery(OrdersPageQueryDTO ordersPageQueryDTO) {
|
||||
PageHelper.startPage(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());
|
||||
Page<Orders> ordersPage = orderMapper.pageQuery(ordersPageQueryDTO);
|
||||
List<OrderVO> list = new ArrayList<>();
|
||||
for (Orders orders : ordersPage) {
|
||||
OrderVO orderVO = new OrderVO();
|
||||
BeanUtils.copyProperties(orders, orderVO);
|
||||
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||
StringBuilder orderDishes = new StringBuilder();
|
||||
for (OrderDetail orderDetail : orderDetailList) {
|
||||
orderDishes.append(orderDetail.getName()).append(",");
|
||||
}
|
||||
orderVO.setOrderDishes(orderDishes.substring(0, orderDishes.length() - 1));
|
||||
list.add(orderVO);
|
||||
}
|
||||
return new PageResult(list.size(), list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderStatisticsVO statistics() {
|
||||
int confirmed = orderMapper.countStatus(Orders.CONFIRMED);
|
||||
int deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);
|
||||
int toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);
|
||||
OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
|
||||
orderStatisticsVO.setConfirmed(confirmed);
|
||||
orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
|
||||
orderStatisticsVO.setToBeConfirmed(toBeConfirmed);
|
||||
return orderStatisticsVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderVO details(Long id) {
|
||||
Orders orders = orderMapper.getById(id);
|
||||
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(orders.getId());
|
||||
StringBuilder orderDishes = new StringBuilder();
|
||||
for (OrderDetail orderDetail : orderDetailList) {
|
||||
orderDishes.append(orderDetail.getName()).append(",");
|
||||
}
|
||||
OrderVO orderVO = new OrderVO();
|
||||
BeanUtils.copyProperties(orders, orderVO);
|
||||
orderVO.setOrderDetailList(orderDetailList);
|
||||
orderVO.setOrderDishes(orderDishes.substring(0, orderDishes.length() - 1));
|
||||
return orderVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirm(OrdersConfirmDTO ordersConfirmDTO) {
|
||||
Orders orders = Orders.builder()
|
||||
.id(ordersConfirmDTO.getId())
|
||||
.status(Orders.CONFIRMED)
|
||||
.build();
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rejection(OrdersRejectionDTO ordersRejectionDTO) {
|
||||
Orders orders = Orders.builder()
|
||||
.id(ordersRejectionDTO.getId())
|
||||
.rejectionReason(ordersRejectionDTO.getRejectionReason())
|
||||
.payStatus(Orders.REFUND)
|
||||
.build();
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelFromAdmin(OrdersCancelDTO ordersCancelDTO) {
|
||||
Orders orders = Orders.builder()
|
||||
.id(ordersCancelDTO.getId())
|
||||
.cancelReason(ordersCancelDTO.getCancelReason())
|
||||
.cancelTime(LocalDateTime.now())
|
||||
.status(Orders.CANCELLED)
|
||||
.payStatus(Orders.REFUND)
|
||||
.build();
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delivery(Long id) {
|
||||
Orders orders = Orders.builder()
|
||||
.id(id)
|
||||
.status(Orders.DELIVERY_IN_PROGRESS)
|
||||
.build();
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Long id) {
|
||||
Orders orders = Orders.builder()
|
||||
.id(id)
|
||||
.status(Orders.COMPLETED)
|
||||
.build();
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,10 +14,13 @@ import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -164,4 +167,14 @@ public class SetmealServiceImpl implements SetmealService {
|
||||
setmealMapper.update(setmeal);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Setmeal> selectSetmealByCategoryId(Integer categoryId) {
|
||||
return setmealMapper.selectByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishItemVO> getDishBySetmealId(Long id) {
|
||||
return dishMapper.selectDishBySetmealId(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.mapper.ShoppingCartMapper;
|
||||
import com.sky.service.ShoppingCartService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCartMapper shoppingCartMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
/**
|
||||
* Adds an item to the shopping cart.
|
||||
*
|
||||
* @param shoppingCartDTO The data transfer object containing details of the item to be added.
|
||||
* It includes the dish ID, setmeal ID, and dish flavor if applicable.
|
||||
*/
|
||||
@Override
|
||||
public void addIntoShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||
//check the item if exists in the shopping cart
|
||||
//fix properties
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
|
||||
if (list != null && !list.isEmpty()){
|
||||
//if exists
|
||||
ShoppingCart cart = list.get(0);
|
||||
cart.setNumber(cart.getNumber() +1);
|
||||
shoppingCartMapper.updateNumberById(cart);
|
||||
}else {
|
||||
//if not,fix the rest properties: name, amount, image
|
||||
//check the item to be added is of dish or set meal
|
||||
Long dishId = shoppingCartDTO.getDishId();
|
||||
if (dishId != null){
|
||||
Dish dish = dishMapper.selectById(dishId);
|
||||
shoppingCart.setName(dish.getName());
|
||||
shoppingCart.setImage(dish.getImage());
|
||||
shoppingCart.setAmount(dish.getPrice());
|
||||
}else {
|
||||
Long setmealId = shoppingCartDTO.getSetmealId();
|
||||
Setmeal setmeal = setmealMapper.selectById(setmealId);
|
||||
shoppingCart.setName(setmeal.getName());
|
||||
shoppingCart.setImage(setmeal.getImage());
|
||||
shoppingCart.setAmount(setmeal.getPrice());
|
||||
}
|
||||
shoppingCart.setNumber(1);
|
||||
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||
|
||||
shoppingCartMapper.insert(shoppingCart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list shopping cart
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ShoppingCart> listShoppingCart() {
|
||||
ShoppingCart shoppingCart = ShoppingCart.builder()
|
||||
.userId(BaseContext.getCurrentId())
|
||||
.build();
|
||||
return shoppingCartMapper.list(shoppingCart);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* clean shopping cart
|
||||
*/
|
||||
@Override
|
||||
public void cleanShoppingCart() {
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
shoppingCartMapper.clean(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* subtract an item from the shopping cart
|
||||
* @param shoppingCartDTO
|
||||
*/
|
||||
@Override
|
||||
public void subtractFromShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||
//construct an object that contains the basic properties : userId, set meal/dish id, dish flavor
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
if (!list.isEmpty()) {
|
||||
shoppingCart = list.get(0);
|
||||
//check the number of shopping cart
|
||||
if (shoppingCart.getNumber() > 1) {
|
||||
shoppingCart.setNumber(shoppingCart.getNumber() - 1);
|
||||
shoppingCartMapper.updateNumberById(shoppingCart);
|
||||
} else {
|
||||
shoppingCartMapper.delete(shoppingCart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,11 @@ spring.servlet.multipart.max-file-size=${spring.servlet.multipart.max-file-size}
|
||||
spring.servlet.multipart.max-request-size=${spring.servlet.multipart.max-request-size}
|
||||
|
||||
sky.wechat.appid=${sky.wechat.appid}
|
||||
sky.wechat.secret=${sky.wechat.secret}
|
||||
sky.wechat.secret=${sky.wechat.secret}
|
||||
sky.wechat.mchid=${sky.wechat.mchid}
|
||||
sky.wechat.mch-serial-no=${sky.wechat.mch-serial-no}
|
||||
sky.wechat.private-key-file-path=${sky.wechat.private-key-file-path}
|
||||
sky.wechat.api-v3-key=${sky.wechat.api-v3-key}
|
||||
sky.wechat.we-chat-pay-cert-file-path=${sky.wechat.we-chat-pay-cert-file-path}
|
||||
sky.wechat.notify-url=${sky.wechat.notify-url}
|
||||
sky.wechat.refund-notify-url=${sky.wechat.refund-notify-url}
|
||||
39
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
39
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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.sky.mapper.AddressBookMapper">
|
||||
<update id="update">
|
||||
update sky_take_out.address_book
|
||||
set city_name = #{cityName},
|
||||
city_code = #{cityCode},
|
||||
consignee = #{consignee},
|
||||
detail = #{detail},
|
||||
district_code = #{districtCode},
|
||||
district_name = #{districtName},
|
||||
label = #{label},
|
||||
phone = #{phone},
|
||||
province_code = #{provinceCode},
|
||||
province_name = #{provinceName},
|
||||
sex = #{sex},
|
||||
<if test="isDefault != null">
|
||||
is_default = #{isDefault},
|
||||
</if>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="list" resultType="com.sky.entity.AddressBook">
|
||||
select * from sky_take_out.address_book
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="isDefault != null">
|
||||
and is_default = #{isDefault}
|
||||
</if>
|
||||
<if test="id != null">
|
||||
and id = #{id}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -55,4 +55,10 @@
|
||||
</foreach>
|
||||
and status = 0
|
||||
</select>
|
||||
<select id="selectDishBySetmealId" resultType="com.sky.vo.DishItemVO">
|
||||
select copies,description,image,d.name
|
||||
from sky_take_out.setmeal_dish s
|
||||
join dish d on d.id = s.dish_id
|
||||
where s.setmeal_id = #{id}
|
||||
</select>
|
||||
</mapper>
|
||||
17
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
17
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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.sky.mapper.OrderDetailMapper">
|
||||
|
||||
<insert id="insertBatch">
|
||||
insert into sky_take_out.order_detail(name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount)
|
||||
VALUES
|
||||
<foreach collection="orderDetails" item="orderDetail" separator=",">
|
||||
(#{orderDetail.name},#{orderDetail.image},#{orderDetail.orderId},#{orderDetail.dishId},#{orderDetail.setmealId},#{orderDetail.dishFlavor},#{orderDetail.number},#{orderDetail.amount})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="getByOrderId" resultType="com.sky.entity.OrderDetail">
|
||||
select * from sky_take_out.order_detail where order_id = #{orderId}
|
||||
</select>
|
||||
</mapper>
|
||||
72
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
72
sky-server/src/main/resources/mapper/OrderMapper.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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.sky.mapper.OrderMapper">
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sky_take_out.orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method,
|
||||
pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason,
|
||||
rejection_reason, cancel_time, estimated_delivery_time, delivery_status,
|
||||
delivery_time, pack_amount, tableware_number, tableware_status)
|
||||
VALUES (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod},
|
||||
#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee}, #{cancelReason},
|
||||
#{rejectionReason}, #{cancelTime}, #{estimatedDeliveryTime}, #{deliveryStatus}, #{deliveryTime},
|
||||
#{packAmount}, #{tablewareNumber}, #{tablewareStatus})
|
||||
</insert>
|
||||
<update id="update" parameterType="com.sky.entity.Orders">
|
||||
update orders
|
||||
<set>
|
||||
<if test="cancelReason != null and cancelReason!='' ">
|
||||
cancel_reason=#{cancelReason},
|
||||
</if>
|
||||
<if test="rejectionReason != null and rejectionReason!='' ">
|
||||
rejection_reason=#{rejectionReason},
|
||||
</if>
|
||||
<if test="cancelTime != null">
|
||||
cancel_time=#{cancelTime},
|
||||
</if>
|
||||
<if test="payStatus != null">
|
||||
pay_status=#{payStatus},
|
||||
</if>
|
||||
<if test="payMethod != null">
|
||||
pay_method=#{payMethod},
|
||||
</if>
|
||||
<if test="checkoutTime != null">
|
||||
checkout_time=#{checkoutTime},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="deliveryTime != null">
|
||||
delivery_time = #{deliveryTime}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<select id="pageQuery" resultType="com.sky.entity.Orders">
|
||||
select * from orders
|
||||
<where>
|
||||
<if test="number != null">
|
||||
and number like concat('%',#{number},'%')
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
and phone like concat('%',#{number},'%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="beginTime != null">
|
||||
and order_time >= #{beginTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and order_time <= #{endTime}
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
</where>
|
||||
order by order_time desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
48
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
48
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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.sky.mapper.ShoppingCartMapper">
|
||||
<insert id="insertBatch">
|
||||
insert into sky_take_out.shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number,
|
||||
amount, create_time) values
|
||||
<foreach collection="shoppingCartList" item="s" separator=",">
|
||||
(#{s.name},#{s.image},#{s.userId},#{s.dishId},#{s.setmealId},#{s.dishFlavor},#{s.number},#{s.amount},#{s.createTime})
|
||||
</foreach>
|
||||
</insert>
|
||||
<delete id="delete">
|
||||
delete from sky_take_out.shopping_cart
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="setmealId != null">
|
||||
and setmeal_id = #{setmealId}
|
||||
</if>
|
||||
<if test="dishId!= null">
|
||||
and dish_id = #{dishId}
|
||||
</if>
|
||||
<if test="dishFlavor != null">
|
||||
and dish_flavor = #{dishFlavor}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
||||
select * from sky_take_out.shopping_cart
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="setmealId != null">
|
||||
and setmeal_id = #{setmealId}
|
||||
</if>
|
||||
<if test="dishId!= null">
|
||||
and dish_id = #{dishId}
|
||||
</if>
|
||||
<if test="dishFlavor != null">
|
||||
and dish_flavor = #{dishFlavor}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user