/* * 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> getMarsHandCardPage(PageParam page,MarsHandCard card) { IPage userInvoicePage = marsHandCardService.getMarsHandCardPage(page,card ); return ServerResponseEntity.success(userInvoicePage); } @GetMapping("/info/{id}") @Operation(summary = "通过刮刮卡id查询刮刮卡信息") @Parameter(name = "id", description = "刮刮卡id" , required = true) public ServerResponseEntity getMarsHandCardById(@PathVariable("id") Long id) { MarsHandCard card = marsHandCardService.getById(id); return ServerResponseEntity.success(card); } @PostMapping("/getMarsHandCards") @Operation(summary = "获取刮刮卡信息") public ServerResponseEntity> getMarsHandCards(@RequestBody MarsHandCard card) { List list = marsHandCardService.getMarsHandCards(card); return ServerResponseEntity.success(list); } @PostMapping("/saveMarsHandCard") @Operation(summary = "新增刮刮卡信息") public ServerResponseEntity 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 qrcodeBind(@RequestBody CardNumberParam cardNumber) { String userId = SecurityUtils.getUser().getUserId(); // String userId = "3"; List 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 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 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 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()); } } }