| | |
| | | package com.ruoyi.goods.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.util.UUIDUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | |
| | | import com.ruoyi.goods.domain.*; |
| | | import com.ruoyi.goods.dto.*; |
| | | import com.ruoyi.goods.service.*; |
| | | import com.ruoyi.goods.utils.MyQrCodeUtil; |
| | | import com.ruoyi.goods.utils.QRCodeUtil; |
| | | import com.ruoyi.goods.vo.GoodDetailVO; |
| | | import com.ruoyi.goods.vo.TGoodsVO; |
| | | import com.ruoyi.goods.vo.TOrderVO; |
| | |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.logging.log4j.core.util.UuidUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.awt.image.BufferedImage; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | } |
| | | |
| | | @PostMapping("/goodList") |
| | | @ApiOperation(value = "商品列表查询", tags = {"学习端-商品列表"}) |
| | | @ApiOperation(value = "商品列表查询", tags = {"家长端-商品列表"}) |
| | | public R<PageInfo<TGoods>> listType(@RequestBody GoodQueryDTO goodQuery) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | List<String> type = goodQuery.getType(); |
| | | String keywords = goodQuery.getKeywords(); |
| | | // 初始化条件构造器 |
| | | QueryWrapper<TGoods> wrapper = new QueryWrapper<>(); |
| | | wrapper = keywords != null && "".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | |
| | | // 类型匹配 todo |
| | | wrapper = type.isEmpty() ? wrapper : wrapper.in(""); |
| | | if (goodQuery.getType()!=null && goodQuery.getType().size()>0){ |
| | | StringBuilder temp = new StringBuilder(""); |
| | | for (String s : goodQuery.getType()) { |
| | | wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | } |
| | | } |
| | | wrapper.eq("isDelete", 0); |
| | | return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper)); |
| | | } |
| | | @PostMapping("/goodListStudy") |
| | | @ApiOperation(value = "商品列表查询", tags = {"学习端"}) |
| | | public R<PageInfo<TGoods>> goodListStudy(@RequestBody GoodQueryDTO goodQuery) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | List<String> type = goodQuery.getType(); |
| | | String keywords = goodQuery.getKeywords(); |
| | | // 初始化条件构造器 |
| | | QueryWrapper<TGoods> wrapper = new QueryWrapper<>(); |
| | | wrapper = keywords != null && "".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | |
| | | // 类型匹配 todo |
| | | if (goodQuery.getType()!=null && goodQuery.getType().size()>0){ |
| | | StringBuilder temp = new StringBuilder(""); |
| | | for (String s : goodQuery.getType()) { |
| | | wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | } |
| | | } |
| | | wrapper.eq("isDelete", 0); |
| | | return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper)); |
| | | } |
| | |
| | | return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid()) |
| | | .orderByDesc(TOrder::getCreateTime).list()); |
| | | } |
| | | @GetMapping("/exchangeRecordParent") |
| | | @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"}) |
| | | public R<List<TOrder>> exchangeRecordParent() { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUser1().getUserid()) |
| | | .orderByDesc(TOrder::getCreateTime).list()); |
| | | } |
| | | |
| | | /** |
| | | * 兑换记录 |
| | | */ |
| | | @GetMapping("/confirm") |
| | | @ApiOperation(value = "确认收货", tags = {"兑换记录"}) |
| | | @ApiOperation(value = "确认收货", tags = {"家长端-兑换记录"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R<Boolean> confirm(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | TOrder byId = orderService.getById(id); |
| | | byId.setState(3); |
| | | return R.ok(orderService.updateById(byId)); |
| | | } |
| | | /** |
| | | * 兑换记录 |
| | | */ |
| | | @GetMapping("/confirmStudy") |
| | | @ApiOperation(value = "确认收货", tags = {"学习端-兑换记录"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R<Boolean> confirmStudy(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | TOrder byId = orderService.getById(id); |
| | | byId.setState(3); |
| | | return R.ok(orderService.updateById(byId)); |
| | |
| | | /** |
| | | * 获取用户收货地址 |
| | | */ |
| | | @GetMapping("/shopAddressParent") |
| | | @ApiOperation(value = "获取用户收货地址", tags = {"家长端-获取用户收货地址"}) |
| | | public R<List<Recipient>> shopAddressParent() { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | tokenService.getLoginUser1().getUserid()).list()); |
| | | } |
| | | /** |
| | | * 设置默认地址 |
| | | */ |
| | | @GetMapping("/setDefault") |
| | | @ApiOperation(value = "设置默认地址", tags = {"家长端-设置默认地址"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R setDefault(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient byId = recipientService.getById(id); |
| | | byId.setIsDefault(1); |
| | | recipientService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 设置默认地址 |
| | | */ |
| | | @GetMapping("/setDefaultStudy") |
| | | @ApiOperation(value = "设置默认地址", tags = {"学习端-设置默认地址"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R setDefaultStudy(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient byId = recipientService.getById(id); |
| | | byId.setIsDefault(1); |
| | | recipientService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 根据地址id 获取详情 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @GetMapping("/getAddressById") |
| | | @ApiOperation(value = "获取地址详情", tags = {"家长端-获取地址详情"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R<Recipient> getAddressById(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient byId = recipientService.getById(id); |
| | | return R.ok(byId); |
| | | } |
| | | /** |
| | | * 根据地址id 获取详情 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @GetMapping("/getAddressByIdStudy") |
| | | @ApiOperation(value = "获取地址详情", tags = {"学习端-获取地址详情"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R<Recipient> getAddressByIdStudy(@RequestParam Integer id) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient byId = recipientService.getById(id); |
| | | return R.ok(byId); |
| | | } |
| | | /** |
| | | * 获取用户收货地址 |
| | | */ |
| | | @GetMapping("/shopAddress") |
| | | @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"}) |
| | | @ApiOperation(value = "获取用户收货地址", tags = {"学习端-获取用户收货地址"}) |
| | | public R<List<Recipient>> shopAddress() { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, |
| | | tokenService.getLoginUserStudy().getUserid()).list()); |
| | | } |
| | |
| | | * 新增收货地址/修改收货地址 |
| | | */ |
| | | @PostMapping("/addressSaveOrUpdate") |
| | | @ApiOperation(value = "学习端-新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) |
| | | @ApiOperation(value = "学习端-新增收货地址/修改收货地址", tags = {"学习端-新增收货地址/修改收货地址"}) |
| | | public R<String> addressSave(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); |
| | | return R.ok(recipientService.addressSaveOrUpdate(recipient)); |
| | | recipientService.addressSaveOrUpdate(recipient); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 新增收货地址/修改收货地址 |
| | | */ |
| | | @PostMapping("/addressSaveOrUpdateParent") |
| | | @ApiOperation(value = "家长端-新增收货地址/修改收货地址", tags = {"家长端-新增收货地址/修改收货地址"}) |
| | | public R<String> addressSaveOrUpdateParent(@RequestBody Recipient recipient) { |
| | | recipient.setUserId(tokenService.getLoginUser1().getUserid()); |
| | | if (recipient.getId() == null){ |
| | | recipientService.updateById(recipient); |
| | | }else{ |
| | | recipientService.save(recipient); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | public R<String> addressDelete(@RequestParam String id) { |
| | | return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | } |
| | | |
| | | /** |
| | | * 修改订单收货地址 |
| | | * |
| | | * @param orderId 订单id |
| | | * 删除收货地址 |
| | | */ |
| | | @GetMapping("/updateOrderAddress") |
| | | @ApiOperation(value = "学习端-修改订单收货地址", tags = {"学习端-修改订单收货地址"}) |
| | | @GetMapping("/addressDeleteParent") |
| | | @ApiOperation(value = "家长端-删除收货地址", tags = {"家长端-删除收货地址"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true) |
| | | }) |
| | | public R<String> addressDeleteParent(@RequestParam String id) { |
| | | return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getOrderAddressParent") |
| | | @ApiOperation(value = "获取修改订单收货地址", tags = {"家长端-获取修改订单收货地址"}) |
| | | public R<List<Recipient>> getOrderAddressParent() { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>() |
| | | .eq("userId", tokenService.getLoginUser1().getUserid())); |
| | | |
| | | return R.ok(userId); |
| | | } |
| | | @GetMapping("/getOrderAddress") |
| | | @ApiOperation(value = "获取修改订单收货地址", tags = {"学习端-获取修改订单收货地址"}) |
| | | public R<List<Recipient>> getOrderAddress() { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>() |
| | | .eq("userId", tokenService.getLoginUserStudy().getUserid())); |
| | | return R.ok(userId); |
| | | } |
| | | @GetMapping("/updateOrderAddressParent") |
| | | @ApiOperation(value = "修改订单收货地址", tags = {"家长端-修改订单收货地址"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "完整收货地址", name = "address", dataType = "String", required = true) |
| | | @ApiImplicitParam(value = "地址信息id", name = "recipientId", dataType = "String", required = true) |
| | | }) |
| | | public R<Boolean> updateOrderAddress(@RequestParam String orderId, |
| | | @RequestParam String address) { |
| | | return R.ok(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) |
| | | .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update()); |
| | | public R updateOrderAddressParent(@RequestParam Integer orderId,@RequestParam Integer recipientId) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient userId = recipientService.getById(recipientId); |
| | | TOrder byId = orderService.getById(orderId); |
| | | byId.setConsigneeName(userId.getAddress()); |
| | | byId.setConsigneePhone(userId.getRecipientPhone()); |
| | | byId.setConsigneeAddress(userId.getAddress()); |
| | | orderService.updateById(byId); |
| | | return R.ok("修改成功"); |
| | | } |
| | | @GetMapping("/updateOrderAddress") |
| | | @ApiOperation(value = "修改订单收货地址", tags = {"学习端-修改订单收货地址"}) |
| | | public R updateOrderAddress(@RequestParam Integer orderId,@RequestParam Integer recipientId) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient userId = recipientService.getById(recipientId); |
| | | TOrder byId = orderService.getById(orderId); |
| | | byId.setConsigneeName(userId.getAddress()); |
| | | byId.setConsigneePhone(userId.getRecipientPhone()); |
| | | byId.setConsigneeAddress(userId.getAddress()); |
| | | orderService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param goodId 商品id |
| | | */ |
| | | @GetMapping("/goodDetail") |
| | | @ApiOperation(value = "学习端-商品详情", tags = {"学习端-商品详情"}) |
| | | @ApiOperation(value = "学习端-商品详情", tags = {"学习端-商城"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> goodDetail(@RequestParam String goodId) { |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | // 商品分类详情 |
| | | List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list(); |
| | | // 已兑换人数 |
| | | int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId()); |
| | | return R.ok(new GoodDetailVO(goods, goodsTypes, number)); |
| | | } |
| | | /** |
| | | * 商品详情 |
| | | * |
| | | * @param goodId 商品id |
| | | */ |
| | | @GetMapping("/goodDetailParent") |
| | | @ApiOperation(value = "商品详情", tags = {"家长端-商城"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> goodDetailParent(@RequestParam String goodId) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | // 商品详情 |
| | | TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | // 商品分类详情 |
| | |
| | | * 商城-立即兑换 |
| | | */ |
| | | @GetMapping("/redeemNow") |
| | | @ApiOperation(value = "学习端-商城立即兑换", tags = {"学习端-商城立即兑换"}) |
| | | @ApiOperation(value = "商城立即兑换", tags = {"学习端-商城"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> redeemNow(@RequestParam String goodId) { |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient recipient = recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()) |
| | | .eq(Recipient::getIsDefault, 1).one(); |
| | | return R.ok(goodsService.redeemNow(goodId, recipient)); |
| | | GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient); |
| | | LocalDateTime currentDateTime = LocalDateTime.now(); |
| | | // 格式化日期和时间信息 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | String formattedDateTime = currentDateTime.format(formatter); |
| | | // 生成随机数,填充剩余位数 |
| | | Random random = new Random(); |
| | | StringBuilder randomPart = new StringBuilder(); |
| | | for (int i = 0; i < 3; i++) { |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母 |
| | | } |
| | | // 组合订单编号 |
| | | String orderNumber = formattedDateTime + randomPart.toString(); |
| | | goodDetailVO.setOrderNumber(orderNumber); |
| | | return R.ok(goodDetailVO); |
| | | } |
| | | /** |
| | | * 商城-立即兑换 |
| | | */ |
| | | @GetMapping("/redeemNowParent") |
| | | @ApiOperation(value = "商城立即兑换", tags = {"家长端-商城"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) |
| | | }) |
| | | public R<GoodDetailVO> redeemNowParent(@RequestParam String goodId) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Recipient recipient = recipientService.lambdaQuery() |
| | | .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid()) |
| | | .eq(Recipient::getIsDefault, 1).one(); |
| | | GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient); |
| | | LocalDateTime currentDateTime = LocalDateTime.now(); |
| | | // 格式化日期和时间信息 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | String formattedDateTime = currentDateTime.format(formatter); |
| | | // 生成随机数,填充剩余位数 |
| | | Random random = new Random(); |
| | | StringBuilder randomPart = new StringBuilder(); |
| | | for (int i = 0; i < 3; i++) { |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母 |
| | | } |
| | | // 组合订单编号 |
| | | String orderNumber = formattedDateTime + randomPart.toString(); |
| | | goodDetailVO.setOrderNumber(orderNumber); |
| | | return R.ok(goodDetailVO); |
| | | } |
| | | |
| | | |
| | |
| | | * @param goodExchange 商品信息 |
| | | */ |
| | | @PostMapping("/goodExchange") |
| | | @ApiOperation(value = "学习端-商品兑换确认", tags = {"学习端-商品兑换确认"}) |
| | | public R<Boolean> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | @ApiOperation(value = "学习端-商品兑换确认", tags = {"家长端-商品兑换确认"}) |
| | | public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) { |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return R.ok(goodsService.goodExchange(goodExchange, recipient)); |
| | | return goodsService.goodExchange1(goodExchange, recipient); |
| | | } |
| | | @PostMapping("/goodExchangeStudy") |
| | | @ApiOperation(value = "学习端-商品兑换确认", tags = {"学习端-商品兑换确认"}) |
| | | public R goodExchangeStudy(@RequestBody GoodExchangeDTO goodExchange) { |
| | | Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); |
| | | return goodsService.goodExchange(goodExchange, recipient); |
| | | } |
| | | |
| | | |
| | | @Autowired |
| | | private StudyClient studyClient; |
| | | @PostMapping("/getOrderInfo/{id}") |