From a623f1eb91b1d89872e3582b5747e9d7096ea225 Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期五, 24 五月 2024 09:01:59 +0800 Subject: [PATCH] 代码提交 --- ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java | 147 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 118 insertions(+), 29 deletions(-) diff --git a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java index 20988ac..12d46fe 100644 --- a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java +++ b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java @@ -6,14 +6,16 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.security.service.TokenService; -import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.goods.domain.*; -import com.ruoyi.goods.dto.GoodExchangeDTO; -import com.ruoyi.goods.dto.GoodQueryDTO; -import com.ruoyi.goods.dto.GoodsTypeQuery; +import com.ruoyi.goods.dto.*; import com.ruoyi.goods.service.*; +import com.ruoyi.goods.vo.GoodDetailVO; import com.ruoyi.goods.vo.TGoodsVO; -import com.ruoyi.system.api.model.LoginUserParent; +import com.ruoyi.goods.vo.TOrderVO; +import com.ruoyi.study.api.domain.TUser; +import com.ruoyi.study.api.feignClient.StudyClient; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -21,10 +23,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; +import java.util.Date; import java.util.List; -import java.util.Map; /** * <p> @@ -47,6 +51,8 @@ private IRecipientService recipientService; @Resource private IRegionService regionService; + @Resource + private TokenService tokenService; @PostMapping("/listType") @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) @@ -165,18 +171,22 @@ @GetMapping("/exchangeRecord") @ApiOperation(value = "兑换记录", tags = {"兑换记录"}) public R<List<TOrder>> exchangeRecord() { - return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, SecurityUtils.getUserId()) + return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid()) .orderByDesc(TOrder::getCreateTime).list()); } + /** * 兑换记录 */ @GetMapping("/confirm") @ApiOperation(value = "确认收货", tags = {"兑换记录"}) - public AjaxResult confirm(@RequestParam Integer id) { + @ApiImplicitParams({ + @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true) + }) + public R<Boolean> confirm(@RequestParam Integer id) { TOrder byId = orderService.getById(id); byId.setState(3); - return AjaxResult.success(orderService.updateById(byId)); + return R.ok(orderService.updateById(byId)); } /** @@ -186,7 +196,7 @@ @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"}) public R<List<Recipient>> shopAddress() { return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, - SecurityUtils.getUserId()).list()); + tokenService.getLoginUserStudy().getUserid()).list()); } /** @@ -195,7 +205,7 @@ @PostMapping("/addressSaveOrUpdate") @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) public R<String> addressSave(@RequestBody Recipient recipient) { - recipient.setUserId(SecurityUtils.getUserId().intValue()); + recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); return R.ok(recipientService.addressSaveOrUpdate(recipient)); } @@ -204,6 +214,9 @@ */ @GetMapping("/addressDelete") @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"}) + @ApiImplicitParams({ + @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true) + }) public R<String> addressDelete(@RequestParam String id) { return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); } @@ -215,7 +228,12 @@ */ @GetMapping("/updateOrderAddress") @ApiOperation(value = "修改订单收货地址", tags = {"修改订单收货地址"}) - public R<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { + @ApiImplicitParams({ + @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true), + @ApiImplicitParam(value = "完整收货地址", name = "address", 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()); } @@ -231,11 +249,12 @@ /** * 可兑换商品推荐 + * 远程调用 */ @GetMapping("/goodRecommend") @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) - public R<List<TGoodsVO>> goodRecommend(String userId) { - return R.ok(goodsService.goodRecommend(userId)); + public R<List<TGoodsVO>> goodRecommend() { + return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid())); } /** @@ -245,21 +264,17 @@ */ @GetMapping("/goodDetail") @ApiOperation(value = "商品详情", tags = {"商品详情"}) - public R<Map<String, Object>> goodDetail(@RequestParam String goodId) { - Map<String, Object> result = new HashMap<>(8); + @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(); - result.put("goodDetail", goods); // 商品分类详情 - result.put("goodTypeDetail", goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list()); + List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list(); // 已兑换人数 - result.put("number", goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId())); - // 用户收货地址 - if (SecurityUtils.getUserId() != null) { - result.put("address", recipientService.lambdaQuery() - .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one()); - } - return R.ok(result); + int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId()); + return R.ok(new GoodDetailVO(goods, goodsTypes, number)); } /** @@ -267,11 +282,16 @@ */ @GetMapping("/redeemNow") @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"}) - public R<Map<String, Object>> redeemNow(@RequestParam String goodId) { + @ApiImplicitParams({ + @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) + }) + public R<GoodDetailVO> redeemNow(@RequestParam String goodId) { Recipient recipient = recipientService.lambdaQuery() - .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one(); + .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()) + .eq(Recipient::getIsDefault, 1).one(); return R.ok(goodsService.redeemNow(goodId, recipient)); } + /** * 商品兑换 @@ -280,10 +300,79 @@ */ @PostMapping("/goodExchange") @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"}) - public R<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { + public R<Boolean> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); return R.ok(goodsService.goodExchange(goodExchange, recipient)); } + @Autowired + private StudyClient studyClient; + @PostMapping("/getOrderInfo/{id}") + @ApiOperation(value = "查看详情", tags = {"后台-订单管理"}) + public R<TOrderVO> getOrderInfo(@PathVariable("id")Integer id) { + TOrder byId = orderService.getById(id); + TGoods byId2 = goodsService.getById(byId.getGoodsId()); + TOrderVO tGoodsVO = new TOrderVO(); + tGoodsVO.setName(byId2.getName()); + BeanUtils.copyProperties(byId,tGoodsVO); + TUser byId1 = studyClient.getUserById(byId.getUserId()).getData(); + tGoodsVO.setUserName(byId1.getName()); + tGoodsVO.setPhone(byId1.getPhone()); + return R.ok(tGoodsVO); + } + @PostMapping("/confirm1") + @ApiOperation(value = "确认发货", tags = {"后台-订单管理"}) + public R getGoodsInfo1(@RequestBody OrderDTO dto) { + TOrder byId = orderService.getById(dto.getId()); + byId.setState(2); + byId.setExpress(dto.getExpress()); + byId.setExpressNumber(dto.getExpressNumber()); + byId.setExpressTime(new Date()); + orderService.updateById(byId); + return R.ok("修改成功"); + } + @PostMapping("/listAll1") + @ApiOperation(value = "列表查询", tags = {"后台-订单管理"}) + public R<PageInfo<TOrderVO>> listAll1(@RequestBody OrderQuery query) throws ParseException { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + if (query.getEndTime()!=null){ + Date parse = format.parse(query.getStartTime()); + Date parse1 = format.parse(query.getEndTime()); + query.setStartTime1(parse); + query.setEndTime1(parse1); + } + List<TOrderVO> list = orderService.listAll(query); + List<TOrderVO> list1 = new ArrayList<>(); + for (TOrderVO tOrderVO : list) { + TUser data = studyClient.getUserById(tOrderVO.getUserId()).getData(); + if (data!=null){ + tOrderVO.setUserName(data.getName()); + tOrderVO.setPhone(data.getPhone()); + } + if (!StringUtils.hasLength(query.getPhone()) && !StringUtils.hasLength(query.getUserName())){ + list1.add(tOrderVO); + continue; + } + // 如果筛选条件输入了电话或者姓名那么需要过滤掉不符合条件的数据 + if (StringUtils.hasLength(query.getPhone()) && StringUtils.hasLength(query.getUserName())){ + if (tOrderVO.getPhone().contains(query.getPhone()) && tOrderVO.getUserName().contains(query.getUserName())){ + list1.add(tOrderVO); + } + }else if (StringUtils.hasLength(query.getPhone())){ + if (tOrderVO.getPhone().contains(query.getPhone())){ + list1.add(tOrderVO); + } + }else if (StringUtils.hasLength(query.getUserName())){ + if (tOrderVO.getUserName().contains(query.getUserName())){ + list1.add(tOrderVO); + } + } + + + } + PageInfo<TOrderVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); + res.setRecords(list1); + return R.ok(res); + } } -- Gitblit v1.7.1