From 910208d1c718b1002434e62fec766dca28afe95e Mon Sep 17 00:00:00 2001 From: gongzuming <gongzuming> Date: 星期六, 14 九月 2024 17:26:41 +0800 Subject: [PATCH] 签到接口 --- src/main/java/com/mzl/flower/web/customer/CustomerSignInController.java | 54 +++++++++++++++++++++++++++ src/main/java/com/mzl/flower/constant/Constants.java | 1 src/main/java/com/mzl/flower/service/point/CustomerPointService.java | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/mzl/flower/constant/Constants.java b/src/main/java/com/mzl/flower/constant/Constants.java index 91e75bf..fc79067 100644 --- a/src/main/java/com/mzl/flower/constant/Constants.java +++ b/src/main/java/com/mzl/flower/constant/Constants.java @@ -482,6 +482,7 @@ consume("消费获取"), activity("活动获取"), giveaway("积分赠送"), + sign("签到"), deduction("积分扣减"), exchange("积分兑换"), expired("积分过期"); diff --git a/src/main/java/com/mzl/flower/service/point/CustomerPointService.java b/src/main/java/com/mzl/flower/service/point/CustomerPointService.java index 1f9dfa0..0d71990 100644 --- a/src/main/java/com/mzl/flower/service/point/CustomerPointService.java +++ b/src/main/java/com/mzl/flower/service/point/CustomerPointService.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.dto.request.point.ChangePointDTO; import com.mzl.flower.dto.request.point.QueryCustomerPointDTO; @@ -14,11 +15,13 @@ import com.mzl.flower.mapper.point.CustomerPointDetailMapper; import com.mzl.flower.mapper.point.CustomerPointMapper; import com.mzl.flower.service.BaseService; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import com.mzl.flower.constant.Constants.*; @@ -142,4 +145,65 @@ //更新汇总表 updateCustomerPoint(detail); } + + public void signIn() { + if(signToday()){ + throw new ValidationException("今天已经签到过了"); + } + int signNum = customerPointDetailMapper + .selectCount(new LambdaQueryWrapper<CustomerPointDetail>() + .eq(CustomerPointDetail::getUserId, SecurityUtils.getUserId()) + .ge(CustomerPointDetail::getRecordDate,LocalDate.now().minusDays(9)) + .eq(CustomerPointDetail::getChangeType,POINT_CHANGE_TYPE.add.name()) + .eq(CustomerPointDetail::getType,POINT_TYPE.sign.name()) + ); + int point = 1; + if(signNum==9){ + point = 3; + } + CustomerPointDetail detail = new CustomerPointDetail(); + Customer customer = getCurrentCustomer(); + detail.setCustomerId(customer.getId()); + detail.setUserId(customer.getUserId()); + detail.setPoint(point); + detail.setRemarks("签到"); + detail.setRecordDate(LocalDate.now()); + detail.setChangeType(POINT_CHANGE_TYPE.add.name()); + detail.setType(POINT_TYPE.sign.name()); + detail.create(SecurityUtils.getUserId()); + customerPointDetailMapper.insert(detail); + + //更新汇总表 + updateCustomerPoint(detail); + } + + public List<CustomerPointDetailDTO> signList(LocalDate startDate, LocalDate endDate) { + LambdaQueryWrapper<CustomerPointDetail> lambdaQueryWrapper = new LambdaQueryWrapper<CustomerPointDetail>() + .eq(CustomerPointDetail::getUserId, SecurityUtils.getUserId()) + .eq(CustomerPointDetail::getChangeType, POINT_CHANGE_TYPE.add.name()) + .eq(CustomerPointDetail::getType, POINT_TYPE.sign.name()); + if(startDate!=null){ + lambdaQueryWrapper.ge(CustomerPointDetail::getRecordDate,startDate); + } + if (endDate != null) { + lambdaQueryWrapper.le(CustomerPointDetail::getRecordDate, endDate); + } + + List<CustomerPointDetail> details = customerPointDetailMapper.selectList(lambdaQueryWrapper); + List<CustomerPointDetailDTO> dtos = new ArrayList<>(); + for (CustomerPointDetail detail : details) { + CustomerPointDetailDTO dto = new CustomerPointDetailDTO(); + BeanUtils.copyProperties(detail, dto); + dtos.add(dto); + } + return dtos; + } + + public Boolean signToday() { + return customerPointDetailMapper.selectCount(new LambdaQueryWrapper<CustomerPointDetail>() + .eq(CustomerPointDetail::getUserId, SecurityUtils.getUserId()) + .eq(CustomerPointDetail::getRecordDate,LocalDate.now()) + .eq(CustomerPointDetail::getChangeType,POINT_CHANGE_TYPE.add.name()) + .eq(CustomerPointDetail::getType,POINT_TYPE.sign.name()))>0; + } } diff --git a/src/main/java/com/mzl/flower/web/customer/CustomerSignInController.java b/src/main/java/com/mzl/flower/web/customer/CustomerSignInController.java new file mode 100644 index 0000000..0463341 --- /dev/null +++ b/src/main/java/com/mzl/flower/web/customer/CustomerSignInController.java @@ -0,0 +1,54 @@ +package com.mzl.flower.web.customer; + +import com.mzl.flower.base.BaseController; +import com.mzl.flower.base.R; +import com.mzl.flower.base.ReturnDataDTO; +import com.mzl.flower.dto.response.point.CustomerPointDetailDTO; +import com.mzl.flower.service.point.CustomerPointService; +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.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; +import java.util.List; + +@RestController +@RequestMapping("/api/customer/point/sign") +@Api(value = "签到-花店", tags = "签到-花店") +@Validated +@Slf4j +public class CustomerSignInController extends BaseController { + + @Autowired + private CustomerPointService customerPointService; + + @PostMapping("/in") + @ApiOperation(value = "签到") + public ResponseEntity<ReturnDataDTO> signIn(){ + customerPointService.signIn(); + return returnData(R.SUCCESS.getCode(), null); + } + + @GetMapping("/list") + @ApiOperation(value = "签到历史") + public ResponseEntity<ReturnDataDTO<List<CustomerPointDetailDTO>>> signList(LocalDate startDate, LocalDate endDate) { + return returnData(R.SUCCESS.getCode(), customerPointService.signList(startDate, endDate)); + } + + @GetMapping("/sign/today") + @ApiOperation(value = "今日是否签到") + public ResponseEntity<ReturnDataDTO<Boolean>> signToday() { + return returnData(R.SUCCESS.getCode(), customerPointService.signToday()); + } + + + + +} -- Gitblit v1.9.3