From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001 From: lee <4766465@qq.com> Date: Wed, 18 Dec 2024 13:27:00 +0800 Subject: [PATCH] init --- yami-shop-api/src/main/java/com/yami/shop/api/controller/MarsHandCardController.java | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 146 insertions(+), 0 deletions(-) diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/MarsHandCardController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/MarsHandCardController.java new file mode 100644 index 0000000..eb9618f --- /dev/null +++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/MarsHandCardController.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ +package com.yami.shop.api.controller; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.yami.shop.bean.model.MarsHandCard; +import com.yami.shop.bean.model.MarsHandCard; +import com.yami.shop.bean.param.CardNumberParam; +import com.yami.shop.bean.vo.MarsHandCardVo; +import com.yami.shop.common.constants.DictConstant; +import com.yami.shop.common.response.ResponseEnum; +import com.yami.shop.common.response.ServerResponseEntity; +import com.yami.shop.common.util.HandCardUtil; +import com.yami.shop.common.util.PageParam; +import com.yami.shop.security.api.util.SecurityUtils; +import com.yami.shop.service.MarsHandCardService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author LGH + */ +@RestController +@RequestMapping("/p/mars/handCard") +@Tag(name = "刮刮卡接口") +@AllArgsConstructor +public class MarsHandCardController { + + @Resource + private MarsHandCardService marsHandCardService; + + @GetMapping("/page") + @Operation(summary = "分页查询刮刮卡列表信息") + public ServerResponseEntity<IPage<MarsHandCard>> getMarsHandCardPage(PageParam<MarsHandCard> page,MarsHandCard card) { + IPage<MarsHandCard> userInvoicePage = marsHandCardService.getMarsHandCardPage(page,card ); + return ServerResponseEntity.success(userInvoicePage); + } + + @GetMapping("/info/{id}") + @Operation(summary = "通过刮刮卡id查询刮刮卡信息") + @Parameter(name = "id", description = "刮刮卡id" , required = true) + public ServerResponseEntity<MarsHandCard> getMarsHandCardById(@PathVariable("id") Long id) { + MarsHandCard card = marsHandCardService.getById(id); + return ServerResponseEntity.success(card); + } + + @PostMapping("/getMarsHandCards") + @Operation(summary = "获取刮刮卡信息") + public ServerResponseEntity<List<MarsHandCard>> getMarsHandCards(@RequestBody MarsHandCard card) { + List<MarsHandCard> list = marsHandCardService.getMarsHandCards(card); + return ServerResponseEntity.success(list); + } + + @PostMapping("/saveMarsHandCard") + @Operation(summary = "新增刮刮卡信息") + public ServerResponseEntity<String> saveMarsHandCard(@RequestBody MarsHandCardVo card) { + Integer num = marsHandCardService.saveMarsHandCards(card); + if(num >0 ){ + return ServerResponseEntity.success(ResponseEnum.OK.getMsg()); + }else{ + return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg()); + } + } + @PostMapping("/qrcodeBind") + @Operation(summary = "扫描刮刮卡绑定用户") + @Transactional(rollbackFor = Exception.class) + public ServerResponseEntity<String> qrcodeBind(@RequestBody CardNumberParam cardNumber) { + String userId = SecurityUtils.getUser().getUserId(); +// String userId = "3"; + List<String> cardNumbers = Arrays.stream(cardNumber.getCardNumbers().split(",")) +// .filter(s -> !s.isEmpty()) + .map(String::trim) // 去除每个字符串的前后空格 + .collect(Collectors.toList()); + for (String str: cardNumbers) { + if(StringUtils.isEmpty(str)){ + return ServerResponseEntity.showFailMsg("请按照规定输入串码!"); + } + } + Integer num = 0; + for (String cnum : cardNumbers) { + //查询刮刮卡串码是否存在 + MarsHandCard handCard = new MarsHandCard(); + handCard.setCardNumber(cnum); +// handCard.setActiveStatus(DictConstant.ACTIVE_STATUS_0); + List<MarsHandCard> marsHandCards = marsHandCardService.getMarsHandCards(handCard); + if (null != marsHandCards && marsHandCards.size() > 0) { + //调用绑定用户 + MarsHandCard card = marsHandCards.get(0); + if(DictConstant.ACTIVE_STATUS_1.equals(card.getActiveStatus())){ + return ServerResponseEntity.showFailMsg(cnum + "该串码已被激活!"); + } + num = marsHandCardService.qrcodeBind(card, userId); + }else{ + return ServerResponseEntity.showFailMsg(cnum + "该刮刮卡不存在!"); + } + } + if (num > 0) { + return ServerResponseEntity.success(ResponseEnum.OK.getMsg()); + } else { + return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg()); + } + } + + @PostMapping("/updateMarsHandCard") + @Operation(summary = "修改刮刮卡信息") + public ServerResponseEntity<String> updateMarsHandCard(@RequestBody MarsHandCard card) { + Integer num = marsHandCardService.updateMarsHandCard(card); + if(num >0 ){ + return ServerResponseEntity.success(ResponseEnum.OK.getMsg()); + }else{ + return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg()); + } + } + + @GetMapping("/delete/{id}") + @Operation(summary = "通过刮刮卡id删除流水信息") + @Parameter(name = "id", description = "寄售流水id" , required = true) + public ServerResponseEntity<String> deleteMarsHandCardById(@PathVariable("id") Long id) { + Integer num = marsHandCardService.deleteMarsHandCard(id); + if(num >0 ){ + return ServerResponseEntity.success(ResponseEnum.OK.getMsg()); + }else{ + return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg()); + } + } + +} -- Gitblit v1.9.3