|
@@ -0,0 +1,81 @@
|
|
|
+package com.example.xiaoshiweixinback.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
|
+import com.example.xiaoshiweixinback.entity.vouchar.VoucherAddDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vouchar.VoucherBatchUpdateDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vouchar.VoucherQueryDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vouchar.VoucherUpdateDTO;
|
|
|
+import com.example.xiaoshiweixinback.domain.Voucher;
|
|
|
+import com.example.xiaoshiweixinback.mapper.VoucherMapper;
|
|
|
+import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author admin
|
|
|
+ * @description 针对表【voucher( 优惠券)】的数据库操作Service实现
|
|
|
+ * @createDate 2024-06-18 23:06:58
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VoucherService extends ServiceImpl<VoucherMapper, Voucher> {
|
|
|
+
|
|
|
+ public Integer addVoucher(VoucherAddDTO voucherAddDTO) {
|
|
|
+ Voucher voucher = new Voucher();
|
|
|
+ BeanUtils.copyProperties(voucherAddDTO, voucher);
|
|
|
+ voucher.insert();
|
|
|
+ return voucher.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer editVoucher(VoucherUpdateDTO voucherUpdateDTO) {
|
|
|
+ Integer id = voucherUpdateDTO.getId();
|
|
|
+ Voucher voucher = this.getById(id);
|
|
|
+ BeanUtils.copyProperties(voucherUpdateDTO, voucher);
|
|
|
+ voucher.updateById();
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Records queryVector(VoucherQueryDTO voucherQueryDTO) {
|
|
|
+ Records records = new Records();
|
|
|
+ Long size = voucherQueryDTO.getSize();
|
|
|
+ Long current = voucherQueryDTO.getCurrent();
|
|
|
+ Integer state = voucherQueryDTO.getState();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<Voucher> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (state != null) {
|
|
|
+ queryWrapper.eq(Voucher::getState, state);
|
|
|
+ }
|
|
|
+ if (size != null && current != null) {
|
|
|
+ Page<Voucher> page = this.page(new Page<>(current, size), queryWrapper);
|
|
|
+ List<Voucher> vouchers = page.getRecords();
|
|
|
+ records.setData(vouchers);
|
|
|
+ records.setCurrent(current);
|
|
|
+ records.setSize(size);
|
|
|
+ records.setTotal(page.getTotal());
|
|
|
+ } else {
|
|
|
+ List<Voucher> vouchers = this.list(queryWrapper);
|
|
|
+ records.setData(vouchers);
|
|
|
+ }
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Integer> updateBatchVoucher(VoucherBatchUpdateDTO voucherBatchUpdateDTO) {
|
|
|
+ Integer state = voucherBatchUpdateDTO.getState();
|
|
|
+ List<Integer> ids = voucherBatchUpdateDTO.getIds();
|
|
|
+ UpdateWrapper<Voucher> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(Voucher::getState, state)
|
|
|
+ .in(Voucher::getId, ids);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|