diff --git a/sql/pay-merchant-menu.sql b/sql/pay-merchant-menu.sql new file mode 100644 index 000000000..cc4a4e761 --- /dev/null +++ b/sql/pay-merchant-menu.sql @@ -0,0 +1,60 @@ +-- 支付模块-商户中心-菜单SQL +-- 菜单 SQL +INSERT INTO `sys_menu` ( + `name`, `permission`,`menu_type`,`sort`, `parent_id`, `path`, `icon`, `component`, + `status`, `creator`,`create_time`, `updater`, `update_time`, `deleted` +) VALUES ('支付管理', '', 1, 4,0, '/pay','pay', NULL, 0, '1', '2021-11-03 10:35:04', '1', '2021-11-03 10:35:04', b'0'); + +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息管理', '', 2, 0, ${table.parentMenuId}, + 'merchant', '', 'pay/merchant/index', 0 +); + +-- 按钮父菜单ID +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息查询', 'pay:merchant:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息创建', 'pay:merchant:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息更新', 'pay:merchant:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息删除', 'pay:merchant:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO `sys_menu`( + `name`, `permission`, `menu_type`, `sort`, `parent_id`, + `path`, `icon`, `component`, `status` +) +VALUES ( + '支付商户信息导出', 'pay:merchant:export', 3, 5, @parentId, + '', '', '', 0 +); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java new file mode 100644 index 000000000..6ec9af43a --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java @@ -0,0 +1,108 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant; + +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*; +import cn.iocoder.yudao.adminserver.modules.pay.convert.merchant.PayMerchantConvert; +import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantService; +import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserUpdateStatusReqVO; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Api(tags = "支付商户信息") +@RestController +@RequestMapping("/pay/merchant") +@Validated +public class PayMerchantController { + + @Resource + private PayMerchantService merchantService; + + @PostMapping("/create") + @ApiOperation("创建支付商户信息") + @PreAuthorize("@ss.hasPermission('pay:merchant:create')") + public CommonResult createMerchant(@Valid @RequestBody PayMerchantCreateReqVO createReqVO) { + return success(merchantService.createMerchant(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新支付商户信息") + @PreAuthorize("@ss.hasPermission('pay:merchant:update')") + public CommonResult updateMerchant(@Valid @RequestBody PayMerchantUpdateReqVO updateReqVO) { + merchantService.updateMerchant(updateReqVO); + return success(true); + } + + @PutMapping("/update-status") + @ApiOperation("修改支付商户状态") + @PreAuthorize("@ss.hasPermission('pay:merchant:update')") + public CommonResult updateMerchantStatus(@Valid @RequestBody PayMerchantUpdateStatusReqVO reqVO) { + merchantService.updateMerchantStatus(reqVO.getId(), reqVO.getStatus()); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除支付商户信息") + @ApiImplicitParam(name = "id", value = "编号", required = true) + @PreAuthorize("@ss.hasPermission('pay:merchant:delete')") + public CommonResult deleteMerchant(@RequestParam("id") Long id) { + merchantService.deleteMerchant(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得支付商户信息") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('pay:merchant:query')") + public CommonResult getMerchant(@RequestParam("id") Long id) { + PayMerchantDO merchant = merchantService.getMerchant(id); + return success(PayMerchantConvert.INSTANCE.convert(merchant)); + } + + @GetMapping("/list") + @ApiOperation("获得支付商户信息列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('pay:merchant:query')") + public CommonResult> getMerchantList(@RequestParam("ids") Collection ids) { + List list = merchantService.getMerchantList(ids); + return success(PayMerchantConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得支付商户信息分页") + @PreAuthorize("@ss.hasPermission('pay:merchant:query')") + public CommonResult> getMerchantPage(@Valid PayMerchantPageReqVO pageVO) { + PageResult pageResult = merchantService.getMerchantPage(pageVO); + return success(PayMerchantConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出支付商户信息 Excel") + @PreAuthorize("@ss.hasPermission('pay:merchant:export')") + @OperateLog(type = EXPORT) + public void exportMerchantExcel(@Valid PayMerchantExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = merchantService.getMerchantList(exportReqVO); + // 导出 Excel + List datas = PayMerchantConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "支付商户信息.xls", "数据", PayMerchantExcelVO.class, datas); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantBaseVO.java new file mode 100644 index 000000000..4d83ff232 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantBaseVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** +* 支付商户信息 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class PayMerchantBaseVO { + + @ApiModelProperty(value = "商户号") + private String no; + + @ApiModelProperty(value = "商户全称", required = true) + @NotNull(message = "商户全称不能为空") + private String name; + + @ApiModelProperty(value = "商户简称", required = true) + @NotNull(message = "商户简称不能为空") + private String shortName; + + @ApiModelProperty(value = "开启状态", required = true) + @NotNull(message = "开启状态不能为空") + private Integer status; + + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantCreateReqVO.java new file mode 100644 index 000000000..2128de88b --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("支付商户信息创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PayMerchantCreateReqVO extends PayMerchantBaseVO { + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java new file mode 100644 index 000000000..80c206c2d --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 支付商户信息 Excel VO + * + * @author 芋艿 + */ +@Data +public class PayMerchantExcelVO { + + @ExcelProperty("商户编号") + private Long id; + + @ExcelProperty("商户号") + private String no; + + @ExcelProperty("商户全称") + private String name; + + @ExcelProperty("商户简称") + private String shortName; + + @ExcelProperty(value = "开启状态",converter = DictConvert.class) + @DictFormat("pay_merchant_status") + private Integer status; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExportReqVO.java new file mode 100644 index 000000000..c6c322282 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExportReqVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "支付商户信息 Excel 导出 Request VO", description = "参数和 PayMerchantPageReqVO 是一致的") +@Data +public class PayMerchantExportReqVO { + + @ApiModelProperty(value = "商户号") + private String no; + + @ApiModelProperty(value = "商户全称") + private String name; + + @ApiModelProperty(value = "商户简称") + private String shortName; + + @ApiModelProperty(value = "开启状态") + private Integer status; + + @ApiModelProperty(value = "备注") + private String remark; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantPageReqVO.java new file mode 100644 index 000000000..8a66ac953 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantPageReqVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("支付商户信息分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PayMerchantPageReqVO extends PageParam { + + @ApiModelProperty(value = "商户号") + private String no; + + @ApiModelProperty(value = "商户全称") + private String name; + + @ApiModelProperty(value = "商户简称") + private String shortName; + + @ApiModelProperty(value = "开启状态") + private Integer status; + + @ApiModelProperty(value = "备注") + private String remark; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantRespVO.java new file mode 100644 index 000000000..ba55458eb --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("支付商户信息 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PayMerchantRespVO extends PayMerchantBaseVO { + + @ApiModelProperty(value = "商户编号", required = true) + private Long id; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateReqVO.java new file mode 100644 index 000000000..031d34fd5 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("支付商户信息更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PayMerchantUpdateReqVO extends PayMerchantBaseVO { + + @ApiModelProperty(value = "商户编号", required = true) + @NotNull(message = "商户编号不能为空") + private Long id; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateStatusReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateStatusReqVO.java new file mode 100644 index 000000000..635876954 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantUpdateStatusReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@ApiModel("商户更新状态 Request VO") +@Data +public class PayMerchantUpdateStatusReqVO { + + @ApiModelProperty(value = "商户编号", required = true, example = "1024") + @NotNull(message = "商户编号不能为空") + private Long id; + + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + private Integer status; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/merchant/PayMerchantConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/merchant/PayMerchantConvert.java new file mode 100644 index 000000000..9483ff120 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/merchant/PayMerchantConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.adminserver.modules.pay.convert.merchant; + +import java.util.*; + +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*; + +/** + * 支付商户信息 Convert + * + * @author 芋艿 + */ +@Mapper +public interface PayMerchantConvert { + + PayMerchantConvert INSTANCE = Mappers.getMapper(PayMerchantConvert.class); + + PayMerchantDO convert(PayMerchantCreateReqVO bean); + + PayMerchantDO convert(PayMerchantUpdateReqVO bean); + + PayMerchantRespVO convert(PayMerchantDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/merchant/PayMerchantMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/merchant/PayMerchantMapper.java new file mode 100644 index 000000000..5abc3a231 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/merchant/PayMerchantMapper.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant; + +import java.util.*; + +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*; + +/** + * 支付商户信息 Mapper + * + * @author 芋艿 + */ +@Mapper +public interface PayMerchantMapper extends BaseMapperX { + + default PageResult selectPage(PayMerchantPageReqVO reqVO) { + return selectPage(reqVO, new QueryWrapperX() + .likeIfPresent("no", reqVO.getNo()) + .likeIfPresent("name", reqVO.getName()) + .likeIfPresent("short_name", reqVO.getShortName()) + .eqIfPresent("status", reqVO.getStatus()) + .eqIfPresent("remark", reqVO.getRemark()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("id")); + } + + default List selectList(PayMerchantExportReqVO reqVO) { + return selectList(new QueryWrapperX() + .likeIfPresent("no", reqVO.getNo()) + .likeIfPresent("name", reqVO.getName()) + .likeIfPresent("short_name", reqVO.getShortName()) + .eqIfPresent("status", reqVO.getStatus()) + .eqIfPresent("remark", reqVO.getRemark()) + .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc("id")); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/enums/PayErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/enums/PayErrorCodeConstants.java new file mode 100644 index 000000000..df39d9efc --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/enums/PayErrorCodeConstants.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.adminserver.modules.pay.enums; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java new file mode 100644 index 000000000..db7926c12 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.adminserver.modules.pay.service.merchant; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 支付商户信息 Service 接口 + * + * @author 芋艿 + */ +public interface PayMerchantService { + + /** + * 创建支付商户信息 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createMerchant(@Valid PayMerchantCreateReqVO createReqVO); + + /** + * 更新支付商户信息 + * + * @param updateReqVO 更新信息 + */ + void updateMerchant(@Valid PayMerchantUpdateReqVO updateReqVO); + + /** + * 删除支付商户信息 + * + * @param id 编号 + */ + void deleteMerchant(Long id); + + /** + * 获得支付商户信息 + * + * @param id 编号 + * @return 支付商户信息 + */ + PayMerchantDO getMerchant(Long id); + + /** + * 获得支付商户信息列表 + * + * @param ids 编号 + * @return 支付商户信息列表 + */ + List getMerchantList(Collection ids); + + /** + * 获得支付商户信息分页 + * + * @param pageReqVO 分页查询 + * @return 支付商户信息分页 + */ + PageResult getMerchantPage(PayMerchantPageReqVO pageReqVO); + + /** + * 获得支付商户信息列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 支付商户信息列表 + */ + List getMerchantList(PayMerchantExportReqVO exportReqVO); + + /** + * 修改商户状态 + * @param id 商户编号 + * @param status 状态 + */ + void updateMerchantStatus(Long id, Integer status); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java new file mode 100644 index 000000000..12981677f --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java @@ -0,0 +1,125 @@ +package cn.iocoder.yudao.adminserver.modules.pay.service.merchant.impl; + +import cn.hutool.core.date.DateUtil; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantCreateReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantExportReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantPageReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantUpdateReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.convert.merchant.PayMerchantConvert; +import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; +import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantService; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import com.google.common.annotations.VisibleForTesting; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +/** + * 支付商户信息 Service 实现类 + * + * @author 芋艿 + */ +@Service +@Validated +public class PayMerchantServiceImpl implements PayMerchantService { + + @Resource + private PayMerchantMapper merchantMapper; + + @Override + public Long createMerchant(PayMerchantCreateReqVO createReqVO) { + // 插入 + PayMerchantDO merchant = PayMerchantConvert.INSTANCE.convert(createReqVO); + // 根据 年月日时分秒毫秒 生成时间戳 + String merchantNo = "M" + DateUtil.format(LocalDateTime.now(),"yyyyMMddHHmmssSSS"); + merchant.setNo(merchantNo); + merchantMapper.insert(merchant); + // 返回 + return merchant.getId(); + } + + @Override + public void updateMerchant(PayMerchantUpdateReqVO updateReqVO) { + // 校验存在 + this.validateMerchantExists(updateReqVO.getId()); + // 更新 + PayMerchantDO updateObj = PayMerchantConvert.INSTANCE.convert(updateReqVO); + merchantMapper.updateById(updateObj); + } + + @Override + public void deleteMerchant(Long id) { + // 校验存在 + this.validateMerchantExists(id); + // 删除 + merchantMapper.deleteById(id); + } + + private void validateMerchantExists(Long id) { + if (merchantMapper.selectById(id) == null) { + throw exception(MERCHANT_NOT_EXISTS); + } + } + + @Override + public PayMerchantDO getMerchant(Long id) { + return merchantMapper.selectById(id); + } + + @Override + public List getMerchantList(Collection ids) { + return merchantMapper.selectBatchIds(ids); + } + + @Override + public PageResult getMerchantPage(PayMerchantPageReqVO pageReqVO) { + return merchantMapper.selectPage(pageReqVO); + } + + @Override + public List getMerchantList(PayMerchantExportReqVO exportReqVO) { + return merchantMapper.selectList(exportReqVO); + } + + /** + * 修改商户状态 + * + * @param id 商户编号 + * @param status 状态 + */ + @Override + public void updateMerchantStatus(Long id, Integer status) { + // 校验商户存在 + this.checkMerchantExists(id); + // 更新状态 + PayMerchantDO merchant = new PayMerchantDO(); + merchant.setId(id); + merchant.setStatus(status); + merchantMapper.updateById(merchant); + } + + /** + * 检查商户是否存在 + * @param id 商户编号 + */ + @VisibleForTesting + public void checkMerchantExists(Long id) { + if (id == null) { + return; + } + PayMerchantDO merchant = merchantMapper.selectById(id); + if (merchant == null) { + throw exception(MERCHANT_NOT_EXISTS); + } + } + + +} diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/merchant/service/PayMerchantServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/merchant/service/PayMerchantServiceTest.java new file mode 100644 index 000000000..a93808921 --- /dev/null +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/merchant/service/PayMerchantServiceTest.java @@ -0,0 +1,192 @@ +package cn.iocoder.yudao.adminserver.modules.pay.merchant.service; + +import cn.hutool.core.util.RandomUtil; +import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantCreateReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantExportReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantPageReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantUpdateReqVO; +import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; +import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.impl.PayMerchantServiceImpl; +import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.MERCHANT_NOT_EXISTS; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static org.junit.jupiter.api.Assertions.*; + +/** +* {@link PayMerchantServiceImpl} 的单元测试类 +* +* @author 芋艿 +*/ +@Import(PayMerchantServiceImpl.class) +public class PayMerchantServiceTest extends BaseDbUnitTest { + + @Resource + private PayMerchantServiceImpl merchantService; + + @Resource + private PayMerchantMapper merchantMapper; + + @Test + public void testCreateMerchant_success() { + // 准备参数 + PayMerchantCreateReqVO reqVO = randomPojo(PayMerchantCreateReqVO.class,o -> + o.setStatus(RandomUtil.randomEle(CommonStatusEnum.values()).getStatus())); + + // 调用 + Long merchantId = merchantService.createMerchant(reqVO); + // 断言 + assertNotNull(merchantId); + // 校验记录的属性是否正确 + PayMerchantDO merchant = merchantMapper.selectById(merchantId); + assertPojoEquals(reqVO, merchant,"no"); + } + + @Test + public void testUpdateMerchant_success() { + // mock 数据 + PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> + o.setStatus(CommonStatusEnum.ENABLE.getStatus())); + merchantMapper.insert(dbMerchant);// @Sql: 先插入出一条存在的数据 + // 准备参数 + PayMerchantUpdateReqVO reqVO = randomPojo(PayMerchantUpdateReqVO.class, o -> { + o.setId(dbMerchant.getId()); // 设置更新的 ID + o.setStatus(CommonStatusEnum.DISABLE.getStatus()); + }); + + // 调用 + merchantService.updateMerchant(reqVO); + // 校验是否更新正确 + PayMerchantDO merchant = merchantMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, merchant); + } + + @Test + public void testUpdateMerchant_notExists() { + // 准备参数 + PayMerchantUpdateReqVO reqVO = randomPojo(PayMerchantUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> merchantService.updateMerchant(reqVO), MERCHANT_NOT_EXISTS); + } + + @Test + public void testDeleteMerchant_success() { + // mock 数据 + PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, + o-> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); + merchantMapper.insert(dbMerchant);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbMerchant.getId(); + + // 调用 + merchantService.deleteMerchant(id); + // 校验数据不存在了 + assertNull(merchantMapper.selectById(id)); + } + + @Test + public void testDeleteMerchant_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> merchantService.deleteMerchant(id), MERCHANT_NOT_EXISTS); + } + + @Test + public void testGetMerchantPage() { + // mock 数据 + PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到 + o.setNo("M1008611"); + o.setName("灿哥的杂货铺"); + o.setShortName("灿灿子"); + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + o.setRemark("灿哥的杂货铺"); + o.setCreateTime(buildTime(2021,11,3)); + }); + merchantMapper.insert(dbMerchant); + // 测试 no 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setNo("M200000"))); + // 测试 name 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setName("斌哥的杂货铺"))); + // 测试 shortName 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setShortName("斌斌子"))); + // 测试 status 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); + // 测试 remark 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setRemark("斌哥的杂货铺"))); + // 测试 createTime 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setCreateTime(buildTime(2022,12,4)))); + // 准备参数 + PayMerchantPageReqVO reqVO = new PayMerchantPageReqVO(); + reqVO.setNo("M1008611"); + reqVO.setName("灿哥的杂货铺"); + reqVO.setShortName("灿灿子"); + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + reqVO.setRemark("灿哥的杂货铺"); + reqVO.setBeginCreateTime(buildTime(2021,11,2)); + reqVO.setEndCreateTime(buildTime(2021,11,4)); + + // 调用 + PageResult pageResult = merchantService.getMerchantPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbMerchant, pageResult.getList().get(0)); + } + + @Test + public void testGetMerchantList() { + // mock 数据 + PayMerchantDO dbMerchant = randomPojo(PayMerchantDO.class, o -> { // 等会查询到 + o.setNo("M1008611"); + o.setName("灿哥的杂货铺"); + o.setShortName("灿灿子"); + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); + o.setRemark("灿哥的杂货铺"); + o.setCreateTime(buildTime(2021,11,3)); + }); + merchantMapper.insert(dbMerchant); + // 测试 no 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setNo("M200000"))); + // 测试 name 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setName("斌哥的杂货铺"))); + // 测试 shortName 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setShortName("斌斌子"))); + // 测试 status 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); + // 测试 remark 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setRemark("斌哥的杂货铺"))); + // 测试 createTime 不匹配 + merchantMapper.insert(ObjectUtils.clone(dbMerchant, o -> o.setCreateTime(buildTime(2022,12,4)))); + // 准备参数 + PayMerchantExportReqVO reqVO = new PayMerchantExportReqVO(); + reqVO.setNo("M1008611"); + reqVO.setName("灿哥的杂货铺"); + reqVO.setShortName("灿灿子"); + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); + reqVO.setRemark("灿哥的杂货铺"); + reqVO.setBeginCreateTime(buildTime(2021,11,2)); + reqVO.setEndCreateTime(buildTime(2021,11,4)); + + // 调用 + List list = merchantService.getMerchantList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbMerchant, list.get(0)); + } + +} diff --git a/yudao-admin-server/src/test/resources/sql/clean.sql b/yudao-admin-server/src/test/resources/sql/clean.sql index 75080b343..e4edd4deb 100644 --- a/yudao-admin-server/src/test/resources/sql/clean.sql +++ b/yudao-admin-server/src/test/resources/sql/clean.sql @@ -24,3 +24,6 @@ DELETE FROM "sys_sms_template"; DELETE FROM "sys_sms_log"; DELETE FROM "sys_error_code"; DELETE FROM "sys_social_user"; + +-- pay 开头的 DB +DELETE FROM pay_merchant; diff --git a/yudao-admin-server/src/test/resources/sql/create_tables.sql b/yudao-admin-server/src/test/resources/sql/create_tables.sql index db67cad23..6c6500386 100644 --- a/yudao-admin-server/src/test/resources/sql/create_tables.sql +++ b/yudao-admin-server/src/test/resources/sql/create_tables.sql @@ -449,3 +449,18 @@ CREATE TABLE IF NOT EXISTS "sys_social_user" ( "deleted" bit NOT NULL DEFAULT FALSE, PRIMARY KEY ("id") ) COMMENT '社交用户'; + +CREATE TABLE IF NOT EXISTS "pay_merchant" ( + "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "no" varchar(32) NOT NULL, + "name" varchar(64) NOT NULL, + "short_name" varchar(64) NOT NULL, + "status" tinyint NOT NULL, + "remark" varchar(255) DEFAULT NULL, + "creator" varchar(64) DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP , + "updater" varchar(64) DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit(1) NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '支付商户信息'; diff --git a/yudao-admin-ui/src/api/pay/merchant.js b/yudao-admin-ui/src/api/pay/merchant.js new file mode 100644 index 000000000..5dc6e96ee --- /dev/null +++ b/yudao-admin-ui/src/api/pay/merchant.js @@ -0,0 +1,67 @@ +import request from '@/utils/request' + +// 创建支付商户信息 +export function createMerchant(data) { + return request({ + url: '/pay/merchant/create', + method: 'post', + data: data + }) +} + +// 更新支付商户信息 +export function updateMerchant(data) { + return request({ + url: '/pay/merchant/update', + method: 'put', + data: data + }) +} + +// 支付商户状态修改 +export function changeMerchantStatus(id, status) { + const data = { + id, + status + } + return request({ + url: '/pay/merchant/update-status', + method: 'put', + data: data + }) +} + +// 删除支付商户信息 +export function deleteMerchant(id) { + return request({ + url: '/pay/merchant/delete?id=' + id, + method: 'delete' + }) +} + +// 获得支付商户信息 +export function getMerchant(id) { + return request({ + url: '/pay/merchant/get?id=' + id, + method: 'get' + }) +} + +// 获得支付商户信息分页 +export function getMerchantPage(query) { + return request({ + url: '/pay/merchant/page', + method: 'get', + params: query + }) +} + +// 导出支付商户信息 Excel +export function exportMerchantExcel(query) { + return request({ + url: '/pay/merchant/export-excel', + method: 'get', + params: query, + responseType: 'blob' + }) +} diff --git a/yudao-admin-ui/src/assets/icons/svg/merchant.svg b/yudao-admin-ui/src/assets/icons/svg/merchant.svg new file mode 100644 index 000000000..f1ecb8127 --- /dev/null +++ b/yudao-admin-ui/src/assets/icons/svg/merchant.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/yudao-admin-ui/src/assets/icons/svg/pay.svg b/yudao-admin-ui/src/assets/icons/svg/pay.svg new file mode 100644 index 000000000..ddab05def --- /dev/null +++ b/yudao-admin-ui/src/assets/icons/svg/pay.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/yudao-admin-ui/src/utils/dict.js b/yudao-admin-ui/src/utils/dict.js index ca1150a59..7c17cceb8 100644 --- a/yudao-admin-ui/src/utils/dict.js +++ b/yudao-admin-ui/src/utils/dict.js @@ -30,6 +30,9 @@ export const DICT_TYPE = { INF_API_ERROR_LOG_PROCESS_STATUS: 'inf_api_error_log_process_status', TOOL_CODEGEN_TEMPLATE_TYPE: 'tool_codegen_template_type', + + // 商户状态 + PAY_MERCHANT_STATUS: 'pay_merchant_status' } /** diff --git a/yudao-admin-ui/src/views/pay/merchant/index.vue b/yudao-admin-ui/src/views/pay/merchant/index.vue new file mode 100644 index 000000000..f57b59f96 --- /dev/null +++ b/yudao-admin-ui/src/views/pay/merchant/index.vue @@ -0,0 +1,295 @@ + + + diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/merchant/PayMerchantDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/merchant/PayMerchantDO.java index d2b20111a..b8edba7e8 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/merchant/PayMerchantDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/merchant/PayMerchantDO.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -29,7 +31,9 @@ public class PayMerchantDO extends BaseDO { /** * 商户号 * 例如说,M233666999 + * 只有新增时插入,不允许修改 */ + @TableField(fill = FieldFill.INSERT) private String no; /** * 商户全称 diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/PayErrorCodeCoreConstants.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/PayErrorCodeCoreConstants.java index d2b940223..a4c88d8c0 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/PayErrorCodeCoreConstants.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/PayErrorCodeCoreConstants.java @@ -28,4 +28,8 @@ public interface PayErrorCodeCoreConstants { ErrorCode PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1007003001, "支付交易拓展单不处于待支付"); ErrorCode PAY_ORDER_EXTENSION_STATUS_IS_NOT_SUCCESS = new ErrorCode(1007003002, "支付订单不处于已支付"); + /** + * ========== 支付商户信息 1-007-004-000 ========== + */ + ErrorCode MERCHANT_NOT_EXISTS = new ErrorCode(1007004000, "支付商户信息不存在"); }