feat:钱包开卡取消绑定、按钮权限

This commit is contained in:
dzc committed 2025-02-17 16:11:51 +08:00
1 parent ec763d0610
commit e32f4ea263
9 files changed
+144 -9

No files matched your search

@@ -0,0 +1,26 @@
package com.bsd.pjcloud.common.core.validation;
public class Group {
public interface APP {
}
public interface ANDROID {
}
public interface ADMIN {
}
public interface SAVE {
}
public interface DEL {
}
public interface UPDATE {
}
public interface FIND {
}
}
@@ -30,7 +30,7 @@ public class HardOrderDto extends HardOrderEntity {
private LocalDate[] createTimeList;
private LocalDate[] payTimeList;
private LocalDateTime[] payTimeList;
/**
* 是否查询购物车列表
@@ -58,6 +58,7 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
.selectAs(HardManagerEntity::getName, HardOrderVo::getHardName)
.selectAs(HardManagerEntity::getType, HardOrderVo::getHardType)
.leftJoin(HardManagerEntity.class, HardManagerEntity::getId, HardOrderEntity::getHardId)
.eqIfExists(HardOrderEntity::getUserId, dto.getUserId())
.eqIfExists(HardOrderEntity::getOrderType, dto.getOrderType())
.eqIfExists(HardOrderEntity::getPayType, dto.getPayType())
.eqIfExists(HardOrderEntity::getOrderStatus, dto.getOrderStatus())
@@ -64,6 +64,11 @@ public class UserDTO extends SysUser {
*/
private String nameOrPhone;
/**
* 用户id
*/
private Long userId;
private List<Long> userIds;
/**
@@ -167,6 +167,9 @@
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
<where>
u.del_flag = '0'
<if test="query.userId != null">
AND u.user_id = #{query.userId}
</if>
<if test="query.username != null and query.username != ''">
<bind name="usernameLike" value="'%'+query.username+'%'"/>
AND u.username LIKE #{usernameLike}
@@ -175,7 +178,7 @@
<bind name="nameLike" value="'%'+query.name+'%'"/>
AND u.name LIKE #{nameLike}
</if>
<if test="query.deptId != null and query.deptId != ''">
<if test="query.deptId != null">
AND u.dept_id = #{query.deptId}
</if>
<if test="query.deptIds != null and query.deptIds.size() != 0">
@@ -0,0 +1,20 @@
package com.bsd.pjcloud.wallet.api.dto;
import com.bsd.pjcloud.common.core.validation.Group;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class WalletActiveBindCardDto {
@NotNull(message = "用户id不能为空", groups = {Group.ADMIN.class})
private Long userId;
@NotNull(message = "饭卡id不能为空", groups = {Group.APP.class})
private Long walletId;
@NotEmpty(message = "卡号不能为空", groups = {Group.APP.class, Group.ADMIN.class})
private String cardNumber;
}
@@ -6,10 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.core.validation.Group;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveBindCardDto;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletActiveVo;
@@ -68,20 +70,40 @@ public class WalletActiveController {
/* ************************************* end android end ************************************* */
/* ************************************* start android start ************************************* */
/* ************************************* start app start ************************************* */
@PostMapping("/app/bind-card")
@SysLog("app绑定饭卡")
@Operation(summary = "app绑定饭卡")
public R<Boolean> appBindCard(@RequestBody WalletActiveDto dto) {
public R<Boolean> appBindCard(@Validated(Group.APP.class) @RequestBody WalletActiveBindCardDto dto) {
PjcloudUser user = SecurityUtils.getUser();
return R.ok(walletActiveService.appBindCard(dto, user));
dto.setUserId(user.getId());
return R.ok(walletActiveService.bindCard(dto));
}
/* ************************************* end app end ************************************* */
@PostMapping("/cancel-bind-card")
@Operation(summary = "admin管理员取消绑定饭卡")
@SysLog("admin管理员取消绑定饭卡")
@Idempotent(info = "正在处理中,请勿重复提交")
@PreAuthorize("@pms.hasPermission('wallet_walletActive_cancel_bind_card')")
public R<Boolean> cancelAdminBindCard(@ParameterObject Long activeId) {
return R.ok(walletActiveService.cancelAdminBindCard(activeId));
}
@PostMapping("/bind-card")
@Operation(summary = "admin管理员绑定饭卡")
@SysLog("admin管理员绑定饭卡")
@Idempotent(info = "正在处理中,请勿重复提交")
@PreAuthorize("@pms.hasPermission('wallet_walletActive_bind_card')")
public R<Boolean> adminBindCard(@Validated(Group.ADMIN.class) @RequestBody WalletActiveBindCardDto dto) {
return R.ok(walletActiveService.adminBindCard(dto));
}
/* ************************************* end android end ************************************* */
@GetMapping("/refresh-avatar")
@Operation(summary = "重新激活")
@SysLog("重新激活")
@Idempotent(info = "正在处理中,请勿重复提交")
@PreAuthorize("@pms.hasPermission('wallet_walletActive_refresh_active')")
public R<Boolean> refreshAvatar(@RequestParam Long id) {
return R.ok(walletActiveService.refreshAvatar(id));
}
@@ -3,6 +3,7 @@ package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveBindCardDto;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletActiveVo;
@@ -36,7 +37,16 @@ public interface WalletActiveService extends IService<WalletActiveEntity> {
* @param dto
* @return
*/
Boolean appBindCard(WalletActiveDto dto, PjcloudUser user);
Boolean bindCard(WalletActiveBindCardDto dto);
Boolean adminBindCard(WalletActiveBindCardDto dto);
/**
* 取消绑定饭卡
*
* @param activeId 开卡id
*/
Boolean cancelAdminBindCard(Long activeId);
/**
* 卡号是否存在
@@ -47,6 +57,7 @@ public interface WalletActiveService extends IService<WalletActiveEntity> {
/**
* 更具卡号查询开卡信息
*
* @return
*/
WalletActiveEntity getByCardNumber(@NotEmpty String cardNumber);
@@ -2,7 +2,10 @@ package com.bsd.pjcloud.wallet.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.bsd.pjcloud.admin.api.entity.SysDept;
@@ -16,6 +19,7 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.MchManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveBindCardDto;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTypeDto;
import com.bsd.pjcloud.wallet.api.entity.MchManageEntity;
@@ -118,7 +122,7 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean appBindCard(WalletActiveDto dto, PjcloudUser user) {
public Boolean bindCard(WalletActiveBindCardDto dto) {
WalletActiveEntity walletActive = getByCardNumber(dto.getCardNumber());
if (ObjectUtil.isEmpty(walletActive)) {
throw new RuntimeException("卡号不存在");
@@ -132,7 +136,7 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
throw new RuntimeException("用户已绑定饭卡");
}
// 更新开卡记录
WalletActiveEntity walletActiveObj = WalletActiveEntity.builder().id(walletActive.getId()).userId(user.getId()).walletId(selfWallet.getId()).walletTypeId(selfWallet.getWalletTypeId()).build();
WalletActiveEntity walletActiveObj = WalletActiveEntity.builder().id(walletActive.getId()).userId(dto.getUserId()).walletId(selfWallet.getId()).walletTypeId(selfWallet.getWalletTypeId()).build();
baseMapper.updateById(walletActiveObj);
// 更新用户钱包
WalletManageEntity walletObj = WalletManageEntity.builder().id(selfWallet.getId()).cardNumber(walletActive.getCardNumber()).activeBindStatus(YesNoEnum.YES.getCode()).activeBindTime(LocalDateTime.now()).build();
@@ -140,6 +144,45 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
return true;
}
@Override
public Boolean adminBindCard(WalletActiveBindCardDto dto) {
// 查询饭卡钱包
WalletManageEntity wallet = walletManageService.getWallet(dto.getUserId(), WalletTypeEnum.EAT);
if (ObjectUtil.isEmpty(wallet)) {
throw new RuntimeException("饭卡钱包不存在");
}
dto.setWalletId(wallet.getId());
return getSelf().bindCard(dto);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean cancelAdminBindCard(Long activeId) {
WalletActiveEntity walletActive = getById(activeId);
if (ObjectUtil.isEmpty(walletActive)) {
throw new RuntimeException("卡号不存在");
}
WalletManageEntity wallet = walletManageService.getWallet(walletActive.getWalletId());
if (ObjectUtil.isEmpty(wallet)) {
throw new RuntimeException("改饭卡没有绑定用户");
}
// 更新开卡记录
LambdaUpdateWrapper<WalletActiveEntity> walletActiveUpdateWrapper = new LambdaUpdateWrapper<WalletActiveEntity>()
.eq(WalletActiveEntity::getId, activeId)
.set(WalletActiveEntity::getUserId, null)
.set(WalletActiveEntity::getWalletId, null)
.set(WalletActiveEntity::getWalletTypeId, null);
baseMapper.update(walletActiveUpdateWrapper);
// 更新用户钱包
LambdaUpdateWrapper<WalletManageEntity> walletUpdateWrapper = new LambdaUpdateWrapper<WalletManageEntity>()
.eq(WalletManageEntity::getId, walletActive.getWalletId())
.set(WalletManageEntity::getCardNumber, null)
.set(WalletManageEntity::getActiveBindStatus, YesNoEnum.NO.getCode())
.set(WalletManageEntity::getActiveBindTime, null);
walletManageService.update(walletUpdateWrapper);
return true;
}
@Override
public Boolean exitCardNumber(Long id, String CardNumber) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<WalletActiveEntity>()
@@ -223,4 +266,8 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
}
return list;
}
private WalletActiveServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}