create:钱包开卡完成

This commit is contained in:
dzc committed 2025-01-02 15:47:56 +08:00
1 parent badada9b65
commit d4a2df19e9
15 files changed
+138 -59

No files matched your search

-28
View File
@@ -1,28 +0,0 @@
-- mch 商户管理
create database `pjcloudx_mch` default character set utf8mb4 collate utf8mb4_general_ci;
DROP TABLE IF EXISTS `mch_manage`;
CREATE TABLE mch_manage
(
id bigint NOT NULL COMMENT '主键',
dept_id bigint NOT NULL COMMENT '绑定的部门id',
name varchar(64) NOT NULL COMMENT '商户名',
types varchar(64) NOT NULL COMMENT '店铺类型,逗号分隔',
logo_pic varchar(256) NOT NULL COMMENT '商户logo图片',
collection_code varchar(256) DEFAULT '' COMMENT '商户收款码,自动生成',
swiper_pic text DEFAULT NULL COMMENT '商户轮播图,逗号分隔',
phone varchar(128) DEFAULT '' COMMENT '商户手机号',
job_start_time timestamp DEFAULT NULL COMMENT '商户开始营业时间',
job_end_time timestamp DEFAULT NULL COMMENT '商户结束营业时间',
address_des varchar(256) DEFAULT NULL COMMENT '商户地址',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT ='商户管理';
CREATE INDEX idx_dept_id ON mch_manage (dept_id);
+7 -7
View File
@@ -15,8 +15,8 @@ CREATE TABLE mch_manage
collection_code varchar(256) DEFAULT '' COMMENT '商户收款码,自动生成',
swiper_pic text DEFAULT NULL COMMENT '商户轮播图,逗号分隔',
phone varchar(128) DEFAULT '' COMMENT '商户手机号',
job_start_time timestamp DEFAULT NULL COMMENT '商户开始营业时间',
job_end_time timestamp DEFAULT NULL COMMENT '商户结束营业时间',
job_start_time time DEFAULT NULL COMMENT '商户开始营业时间',
job_end_time time DEFAULT NULL COMMENT '商户结束营业时间',
address_des varchar(256) DEFAULT NULL COMMENT '商户地址',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
@@ -88,9 +88,9 @@ DROP TABLE IF EXISTS wallet_active;
CREATE TABLE wallet_active
(
id bigint NOT NULL COMMENT '主键',
user_id bigint NOT NULL COMMENT '用户id',
wallet_id bigint NOT NULL COMMENT '钱包id',
wallet_type_id bigint NOT NULL COMMENT '饭卡类型id',
user_id bigint DEFAULT NULL COMMENT '用户id',
wallet_id bigint DEFAULT NULL COMMENT '钱包id',
wallet_type_id bigint DEFAULT NULL COMMENT '饭卡类型id',
dept_id bigint NOT NULL COMMENT '部门id',
merchant_id bigint NOT NULL COMMENT '商户id',
card_number varchar(128) NOT NULL COMMENT '用户卡号',
@@ -106,7 +106,6 @@ CREATE TABLE wallet_active
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='钱包开卡';
CREATE INDEX idx_dept_id ON wallet_active (user_id);
CREATE INDEX idx_dept_id ON wallet_active (dept_id);
-- ----------------------------
-- Table structure for wallet_freeze
@@ -193,10 +192,11 @@ CREATE TABLE wallet_recharge_apply
COLLATE = utf8mb4_general_ci COMMENT ='充值申请表';
CREATE INDEX idx_dept_id ON wallet_recharge_apply (user_id);
DROP TABLE IF EXISTS wallet_recharge_import;
CREATE TABLE wallet_recharge_import
(
id bigint NOT NULL COMMENT '编号',
user_id bigint NOT NULL COMMENT '用户id',
user_id bigint default NULL COMMENT '用户id',
apply_id bigint NOT NULL COMMENT '申请id',
before_price int DEFAULT NULL COMMENT '导入前的金额',
price int NOT NULL COMMENT '交易金额, 单位分',
@@ -16,4 +16,6 @@ public class MchManageDto extends MchManageEntity {
private List<Long> deptIds;
private List<Long> ids;
}
@@ -7,6 +7,8 @@ import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
@Data
public class WalletActiveDto extends WalletActiveEntity {
@@ -19,7 +21,7 @@ public class WalletActiveDto extends WalletActiveEntity {
@NotNull(message = "商户id不能为空")
private Long merchantId;
@NotNull(message = "钱包类型id不能为空")
private Long walletTypeId;
private List<Long> userIds;
}
@@ -1,12 +1,15 @@
package com.bsd.pjcloud.wallet.api.entity;
import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
import java.time.LocalTime;
/**
* 商户管理
@@ -75,13 +78,15 @@ public class MchManageEntity extends Model<MchManageEntity> {
* 商户开始营业时间
*/
@Schema(description="商户开始营业时间")
private LocalDateTime jobStartTime;
@JsonFormat(pattern = DatePattern.NORM_TIME_PATTERN)
private LocalTime jobStartTime;
/**
* 商户结束营业时间
*/
@Schema(description="商户结束营业时间")
private LocalDateTime jobEndTime;
@JsonFormat(pattern = DatePattern.NORM_TIME_PATTERN)
private LocalTime jobEndTime;
/**
* 商户地址
@@ -15,12 +15,12 @@ import java.util.Map;
public class MchDataUtil {
public <T extends BaseMchInterface> List<T> convertMchList(List<T> list, Map<Long, MchManageVo> map) {
return CollectionUtils.convertList(list, v -> convertMch(v, map.get(v.getMchId())));
return CollectionUtils.convertList(list, v -> convertMch(v, map.get(v.getMerchantId())));
}
public <T extends BaseMchInterface> T convertMch(T v, MchManageVo vo) {
if (ObjectUtil.isEmpty(vo)) return v;
v.setMchName(vo.getName());
v.setMerchantName(vo.getName());
return v;
}
@@ -1,8 +1,30 @@
package com.bsd.pjcloud.wallet.api.vo;
import com.bsd.pjcloud.admin.api.vo.base.BaseDeptInterface;
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.vo.base.BaseMchInterface;
import lombok.Data;
@Data
public class WalletActiveVo extends WalletActiveEntity {
public class WalletActiveVo extends WalletActiveEntity implements BaseUserInterface, BaseDeptInterface, BaseMchInterface {
/**
* 用户相关
*/
private String username;
private String userMobile;
private String userAvatar;
/**
* 部门相关
*/
private String deptName;
/**
* 商户相关
*/
private String merchantName;
}
@@ -5,15 +5,15 @@ public interface BaseMchInterface {
/**
* 商户id
*/
Long getMchId();
Long getMerchantId();
void setMchId(Long dchId);
void setMerchantId(Long dchId);
/**
* 商户名
*/
String getMchName();
String getMerchantName();
void setMchName(String dchName);
void setMerchantName(String dchName);
}
@@ -10,10 +10,8 @@ import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeCodeEnum;
import com.bsd.pjcloud.wallet.api.dto.MchManageDto;
import com.bsd.pjcloud.wallet.api.entity.MchManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.service.MchManageService;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -42,7 +40,7 @@ import java.util.List;
public class MchManageController {
private final MchManageService mchManageService;
/* ************************************* start 远程调用 start ************************************* */
@Inner
@@ -11,6 +11,7 @@ import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.service.WalletActiveService;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -23,8 +24,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* 钱包开卡
@@ -45,7 +44,7 @@ public class WalletActiveController {
@PostMapping("/fast-create-card")
@Operation(summary = "一键开卡")
@Idempotent(info = "正在开卡中,请勿重复提交")
public R<Boolean> fastCreateCard(WalletActiveDto dto) {
public R<Boolean> fastCreateCard(@Valid @RequestBody WalletActiveDto dto) {
walletActiveService.fastCreateCard(dto);
return R.ok(true);
}
@@ -65,6 +64,20 @@ public class WalletActiveController {
return R.ok(walletActiveService.page(page, wrapper));
}
/**
* 分页复杂查询
*
* @param page 分页对象
* @param walletActive 钱包开卡
* @return
*/
@Operation(summary = "分页复杂查询", description = "分页复杂查询")
@GetMapping("/page-join")
@PreAuthorize("@pms.hasPermission('wallet_walletActive_view')")
public R getWalletActivePageJoin(@ParameterObject Page page, @ParameterObject WalletActiveDto dto) {
return R.ok(walletActiveService.pageJoin(page, dto));
}
/**
* 通过id查询钱包开卡
@@ -27,7 +27,8 @@ public interface MchManageMapper extends PjcloudBaseMapper<MchManageEntity> {
MPJLambdaQueryWrapper<MchManageEntity> wrapper = new MPJLambdaQueryWrapper<MchManageEntity>()
.selectAll(MchManageEntity.class)
.likeIfExists(MchManageEntity::getName, dto.getName())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), MchManageEntity::getDeptId, dto.getDeptIds());
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), MchManageEntity::getDeptId, dto.getDeptIds())
.in(ObjectUtil.isNotEmpty(dto.getIds()), MchManageEntity::getId, dto.getIds());
return selectJoinList(MchManageVo.class, wrapper);
}
}
@@ -1,11 +1,23 @@
package com.bsd.pjcloud.wallet.mapper;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletActiveVo;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WalletActiveMapper extends PjcloudBaseMapper<WalletActiveEntity> {
default Page<WalletActiveVo> pageJoin(Page page, WalletActiveDto dto) {
MPJLambdaQueryWrapper<WalletActiveEntity> wrapper = new MPJLambdaQueryWrapper<WalletActiveEntity>()
.selectAll(WalletActiveEntity.class)
.likeIfExists(WalletActiveEntity::getCardNumber, dto.getCardNumber())
.eqIfExists(WalletActiveEntity::getIsActiveHardware, dto.getIsActiveHardware())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletActiveEntity::getId, dto.getUserIds());
return selectJoinPage(page, WalletActiveVo.class, wrapper);
}
}
@@ -1,8 +1,10 @@
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.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletActiveVo;
public interface WalletActiveService extends IService<WalletActiveEntity> {
/**
@@ -11,4 +13,6 @@ public interface WalletActiveService extends IService<WalletActiveEntity> {
* @param dto
*/
void fastCreateCard(WalletActiveDto dto);
Page<WalletActiveVo> pageJoin(Page page, WalletActiveDto dto);
}
@@ -69,7 +69,7 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
throw new CheckedException("商户名不能重复");
}
if (existDeptId(dto.getDeptId(), null)) {
throw new CheckedException("改部门已经绑定过商户");
throw new CheckedException("该部门已经绑定过商户");
}
baseMapper.insert(dto);
try {
@@ -3,14 +3,29 @@ package com.bsd.pjcloud.wallet.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.exception.CheckedException;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeCodeEnum;
import com.bsd.pjcloud.wallet.api.dto.MchManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletActiveDto;
import com.bsd.pjcloud.wallet.api.entity.MchManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.utils.MchDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletActiveVo;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.mapper.WalletActiveMapper;
import com.bsd.pjcloud.wallet.service.MchManageService;
import com.bsd.pjcloud.wallet.service.WalletActiveService;
import com.bsd.pjcloud.wallet.service.WalletTypeService;
import lombok.RequiredArgsConstructor;
@@ -21,6 +36,7 @@ import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 钱包开卡
@@ -35,16 +51,21 @@ import java.util.List;
public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, WalletActiveEntity> implements WalletActiveService {
private final WalletTypeService walletTypeService;
private final MchManageService mchManageService;
private final RemoteUserService userService;
private final RemoteDeptService deptService;
@Override
@Transactional(rollbackFor = Exception.class)
public void fastCreateCard(WalletActiveDto dto) {
Long count = dto.getCount();
// 查询饭卡钱包类型
WalletTypeEntity walletType = walletTypeService.getById(dto.getWalletTypeId());
WalletTypeEntity walletType = walletTypeService.getByUniqueCode(WalletTypeCodeEnum.CANTEEN);
if (ObjectUtil.isEmpty(walletType)) throw new CheckedException("钱包类型不存在");
// 查询商户
MchManageEntity mchManage = mchManageService.getById(dto.getMerchantId());
if (ObjectUtil.isEmpty(mchManage)) throw new CheckedException("商户不存在");
int startNum = 1;
WalletActiveEntity last = getLast();
if (ObjectUtil.isNotEmpty(last)) startNum = last.getCardSort();
@@ -53,16 +74,43 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
startNum += 1;
WalletActiveEntity item = new WalletActiveEntity();
String cardNumber = "hq" + String.format("%06d", startNum) + RandomUtil.randomString(RandomUtil.BASE_CHAR, 4);
item.setCardSort(startNum);
item.setCardNumber(cardNumber);
item.setWalletTypeId(walletType.getId());
item.setDeptId(null);
item.setMerchantId(null);
item.setDeptId(mchManage.getDeptId());
item.setMerchantId(mchManage.getId());
item.setIsActiveHardware(YesNoEnum.NO.getCode());
batchSaveList.add(item);
}
baseMapper.insert(batchSaveList);
}
@Override
public Page<WalletActiveVo> pageJoin(Page page, WalletActiveDto dto) {
Page<WalletActiveVo> list = baseMapper.pageJoin(page, dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户
List<Long> userIds = list.getRecords().stream().map(WalletActiveVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(page.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.getRecords().stream().map(WalletActiveVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(page.getRecords(), deptList.getData());
}
// 商户
List<Long> mchIds = list.getRecords().stream().map(WalletActiveVo::getMerchantId).distinct().toList();
List<MchManageVo> mchList = mchManageService.list(MchManageDto.builder().ids(mchIds).build());
if (ObjectUtil.isNotEmpty(mchList)) {
MchDataUtil.convertMchList(page.getRecords(), CollectionUtils.convertMap(mchList, MchManageVo::getId));
}
}
return list;
}
private WalletActiveEntity getLast() {
LambdaQueryWrapper<WalletActiveEntity> query = new LambdaQueryWrapper<WalletActiveEntity>();
query.orderByDesc(WalletActiveEntity::getId).last("LIMIT 1");