Ver código fonte

优惠卷查询添加字段

xlq 2 dias atrás
pai
commit
215bbf8ce9

+ 7 - 0
src/main/java/com/qmrb/system/pojo/vo/CouponVO.java

@@ -19,6 +19,13 @@ import lombok.Data;
 @Data
 public class CouponVO {
 
+
+    /**
+     * 车牌号
+     */
+    @Schema(description = "车牌号",type="String")
+    private String carNumber;
+
     /**
      * 优惠券ID(主键)
      */

+ 100 - 83
src/main/java/com/qmrb/system/service/impl/CouponServiceImpl.java

@@ -13,8 +13,10 @@ import java.util.stream.Collectors;
 import com.qmrb.system.common.util.AesUtils;
 import com.qmrb.system.framework.security.CaConstants;
 import com.qmrb.system.framework.security.util.SecurityUtils;
+import com.qmrb.system.pojo.entity.BarnRecord;
 import com.qmrb.system.pojo.entity.Contract;
 import com.qmrb.system.pojo.entity.SysUser;
+import com.qmrb.system.service.IBarnRecordService;
 import com.qmrb.system.service.IContractService;
 import com.qmrb.system.service.SysUserService;
 import com.qmrb.system.service.UserService;
@@ -52,111 +54,126 @@ import javax.swing.*;
 @Service
 public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {
 
-	@Autowired
-	private CouponConverter converter;
-	
-	@Autowired
-	private IContractService contractService;
-	
-	@Autowired
-	private SysUserService userService;
-
-	@Autowired
-	private RedisTemplate redisTemplate;
-
-	/**分页查询
-	 * */
-	@Override
-	public Page<CouponVO> getPage(CouponQuery queryParams) {
-		// 查询参数
+    @Autowired
+    private CouponConverter converter;
+
+    @Autowired
+    private IContractService contractService;
+
+    @Autowired
+    private SysUserService userService;
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    @Autowired
+    private IBarnRecordService barnRecordService;
+
+    /**
+     * 分页查询
+     */
+    @Override
+    public Page<CouponVO> getPage(CouponQuery queryParams) {
+        // 查询参数
         int pageNum = queryParams.getPageNum();
         int pageSize = queryParams.getPageSize();
         Integer status = queryParams.getStatus();
-        //String keywords = queryParams.getKeywords();
+        // String keywords = queryParams.getKeywords();
 
         // 查询数据
         Page<Coupon> dictItemPage = this.page(
                 new Page<>(pageNum, pageSize),
                 new LambdaQueryWrapper<Coupon>()
-                	.eq(status != null, Coupon::getStatus,status)
-                	//.like(StrUtil.isNotBlank(keywords), Coupon::getCategoryName, keywords)
+                        .eq(status != null, Coupon::getStatus, status)
+                //.like(StrUtil.isNotBlank(keywords), Coupon::getCategoryName, keywords)
         );
 
         // 实体转换
         Page<CouponVO> pageResult = converter.entity2Page(dictItemPage);
-        return pageResult;
-	}
-
-	/**
-	 * 保存表单
-	 * */
-	@Override
-	public CouponForm saveForm(@Valid CouponForm form) {
-		
-		// 校验是否已领取过优惠券
-		List<Coupon> list = this.list(new LambdaQueryWrapper<Coupon>().eq(Coupon::getToUserId, SecurityUtils.getUserId()).eq(Coupon::getGoodsId, form.getGoodsId()));
-		Assert.isTrue(CollectionUtil.isEmpty(list), "已存在领取的优惠券");
-
-
-		Object contractIdEnc = redisTemplate.opsForValue().get(form.getContractIdEnc());
-		Assert.isTrue(contractIdEnc != null, "二维码已过期");
-		String contractId = contractIdEnc.toString();
-		form.setContractId(Long.parseLong(contractId));
-		// 根据协议id生成优惠券
-		if(form.getContractId() != null){
-			Contract contract = contractService.getById(form.getContractId());
-			Assert.isTrue(contract != null, "关联协议数据不存在");
-			SysUser user = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getContractId, form.getContractId()));
-			Assert.isTrue(user != null, "关联协议用户数据不存在");
-			form.setFromUserId(user.getId());
-			form.setToUserId(SecurityUtils.getUserId());
-			form.setScenes(1);//使用场景(1-停车场, 2-其他场景
-			// 1 扫码抵用金额 2扫码抵用时长
-			if(contract.getScanType().equals("1")){
-				form.setDenomination(contract.getDiscountAmount());
-				form.setCouponType(1);//优惠券类型(1-金额券, 2-时长券)
-			}else if(contract.getScanType().equals("2")){
-				form.setDenomination(contract.getDiscountMinute() != null ? new BigDecimal(contract.getDiscountMinute()) : BigDecimal.ZERO);
-				form.setCouponType(2);//优惠券类型(1-金额券, 2-时长券)
+        List<CouponVO> records = pageResult.getRecords();
+        if (CollectionUtil.isNotEmpty(records)) {
+            for (CouponVO record : records) {
+				List<BarnRecord> list = barnRecordService.list(new LambdaQueryWrapper<BarnRecord>().eq(BarnRecord::getId, record.getGoodsId()).orderByDesc(BarnRecord::getCreateTime));
+				if (CollectionUtil.isNotEmpty(list)) {
+					record.setCarNumber(list.get(0).getCarNumber());
+				}
 			}
-			form.setEffectiveTime(LocalDateTime.now());
-			// 将 Date 转换为 Instant
-			Instant outInstant = contract.getEndDate().toInstant();
-
-			// 将 Instant 转换为 LocalDateTime(假设使用系统默认时区)
-			LocalDateTime outDateTime = outInstant.atZone(ZoneId.systemDefault()).toLocalDateTime();
-			form.setExpireTime(outDateTime);
-			form.setStatus(0);//状态(0-已使用, 1-未使用, 2-锁定)
-			
-		}
-		// 实体对象转换 form->entity
-		Coupon entity = converter.form2Entity(form);
+        }
+        return pageResult;
+    }
+
+    /**
+     * 保存表单
+     */
+    @Override
+    public CouponForm saveForm(@Valid CouponForm form) {
+
+        // 校验是否已领取过优惠券
+        List<Coupon> list = this.list(new LambdaQueryWrapper<Coupon>().eq(Coupon::getToUserId, SecurityUtils.getUserId()).eq(Coupon::getGoodsId, form.getGoodsId()));
+        Assert.isTrue(CollectionUtil.isEmpty(list), "已存在领取的优惠券");
+
+
+        Object contractIdEnc = redisTemplate.opsForValue().get(form.getContractIdEnc());
+        Assert.isTrue(contractIdEnc != null, "二维码已过期");
+        String contractId = contractIdEnc.toString();
+        form.setContractId(Long.parseLong(contractId));
+        // 根据协议id生成优惠券
+        if (form.getContractId() != null) {
+            Contract contract = contractService.getById(form.getContractId());
+            Assert.isTrue(contract != null, "关联协议数据不存在");
+            SysUser user = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getContractId, form.getContractId()));
+            Assert.isTrue(user != null, "关联协议用户数据不存在");
+            form.setFromUserId(user.getId());
+            form.setToUserId(SecurityUtils.getUserId());
+            form.setScenes(1);// 使用场景(1-停车场, 2-其他场景
+            // 1 扫码抵用金额 2扫码抵用时长
+            if (contract.getScanType().equals("1")) {
+                form.setDenomination(contract.getDiscountAmount());
+                form.setCouponType(1);// 优惠券类型(1-金额券, 2-时长券)
+            } else if (contract.getScanType().equals("2")) {
+                form.setDenomination(contract.getDiscountMinute() != null ? new BigDecimal(contract.getDiscountMinute()) : BigDecimal.ZERO);
+                form.setCouponType(2);// 优惠券类型(1-金额券, 2-时长券)
+            }
+            form.setEffectiveTime(LocalDateTime.now());
+            // 将 Date 转换为 Instant
+            Instant outInstant = contract.getEndDate().toInstant();
+
+            // 将 Instant 转换为 LocalDateTime(假设使用系统默认时区)
+            LocalDateTime outDateTime = outInstant.atZone(ZoneId.systemDefault()).toLocalDateTime();
+            form.setExpireTime(outDateTime);
+            form.setStatus(0);// 状态(0-已使用, 1-未使用, 2-锁定)
+
+        }
+        // 实体对象转换 form->entity
+        Coupon entity = converter.form2Entity(form);
         // 持久化
         this.save(entity);
         CouponForm result = converter.entity2Form(entity);
         return result;
-	}
-
-	/**更新
-	 * */
-	@Override
-	public boolean updateForm(Long id, CouponForm form) {
-		Coupon entity = converter.form2Entity(form);
-		entity.setId(id);
+    }
+
+    /**
+     * 更新
+     */
+    @Override
+    public boolean updateForm(Long id, CouponForm form) {
+        Coupon entity = converter.form2Entity(form);
+        entity.setId(id);
         boolean result = this.updateById(entity);
         return result;
-	}
-
-	/**获取表单数据
-	 * */
-	@Override
-	public CouponForm getFormData(Long id) {
-		// 获取entity
-		Coupon entity = this.getById(id);
+    }
+
+    /**
+     * 获取表单数据
+     */
+    @Override
+    public CouponForm getFormData(Long id) {
+        // 获取entity
+        Coupon entity = this.getById(id);
         Assert.isTrue(entity != null, "优惠券表不存在");
 
         // 实体转换
         CouponForm form = converter.entity2Form(entity);
         return form;
-	}
+    }
 }