From 22abfe68fa5b8a2713369225754759a68bdb2a30 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Thu, 29 May 2025 00:59:13 +0800
Subject: [PATCH] 商户

---
 oying-system/src/main/java/com/oying/modules/system/service/impl/MerchantsServiceImpl.java |   86 ++++++++++++
 oying-system/src/main/resources/mapper/system/MerchantsMapper.xml                          |   48 ++++++
 oying-system/src/main/java/com/oying/modules/system/mapper/MerchantsMapper.java            |   22 +++
 oying-system/src/main/java/com/oying/modules/system/rest/MerchantsController.java          |   73 ++++++++++
 oying-system/src/main/java/com/oying/modules/system/domain/Merchants.java                  |   68 +++++++++
 oying-system/src/main/java/com/oying/modules/system/service/MerchantsService.java          |   59 ++++++++
 oying-system/src/main/java/com/oying/modules/system/domain/dto/MerchantsQueryCriteria.java |   36 +++++
 7 files changed, 392 insertions(+), 0 deletions(-)

diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/Merchants.java b/oying-system/src/main/java/com/oying/modules/system/domain/Merchants.java
new file mode 100644
index 0000000..139f7b5
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/domain/Merchants.java
@@ -0,0 +1,68 @@
+package com.oying.modules.system.domain;
+
+import com.oying.base.BaseEntity;
+import cn.hutool.core.bean.BeanUtil;
+import io.swagger.annotations.ApiModelProperty;
+import cn.hutool.core.bean.copier.CopyOptions;
+import java.sql.Timestamp;
+import javax.validation.constraints.NotBlank;
+import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+* @description /
+* @author lixin
+* @date 2025-05-29
+**/
+@Getter
+@Setter
+@TableName("sys_merchants")
+public class Merchants extends BaseEntity implements Serializable {
+
+    @TableId(value = "merchants_id", type = IdType.AUTO)
+    @ApiModelProperty(value = "ID")
+    private Long merchantsId;
+
+    @NotBlank
+    @ApiModelProperty(value = "名称")
+    private String merchantName;
+
+    @NotBlank
+    @ApiModelProperty(value = "商户编码")
+    private String merchantCode;
+
+    @NotBlank
+    @ApiModelProperty(value = "营业执照号")
+    private String businessLicense;
+
+    @NotBlank
+    @ApiModelProperty(value = "营业执照号路径")
+    private String businessLicensePath;
+
+    @NotBlank
+    @ApiModelProperty(value = "联系手机")
+    private String contactMobile;
+
+    @ApiModelProperty(value = "排序")
+    private Integer merchantsSort;
+
+    @ApiModelProperty(value = "状态")
+    private String enabled = "1";
+
+    @ApiModelProperty(value = "审核人")
+    private String authUser;
+
+    @ApiModelProperty(value = "审核时间")
+    private Timestamp authTime;
+
+    @ApiModelProperty(value = "审核信息")
+    private String authMessage;
+
+    public void copy(Merchants source){
+        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
+    }
+}
diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/dto/MerchantsQueryCriteria.java b/oying-system/src/main/java/com/oying/modules/system/domain/dto/MerchantsQueryCriteria.java
new file mode 100644
index 0000000..f56c7a0
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/domain/dto/MerchantsQueryCriteria.java
@@ -0,0 +1,36 @@
+package com.oying.modules.system.domain.dto;
+
+import lombok.Data;
+import java.sql.Timestamp;
+import java.util.List;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+* @author lixin
+* @date 2025-05-29
+**/
+@Data
+public class MerchantsQueryCriteria{
+
+    @ApiModelProperty(value = "页码", example = "1")
+    private Integer page = 1;
+
+    @ApiModelProperty(value = "每页数据量", example = "10")
+    private Integer size = 10;
+
+    @ApiModelProperty(value = "名称")
+    private String merchantName;
+
+    @ApiModelProperty(value = "商户编码")
+    private String merchantCode;
+
+    @ApiModelProperty(value = "营业执照号")
+    private String businessLicense;
+
+    @ApiModelProperty(value = "联系手机")
+    private String contactMobile;
+
+    @ApiModelProperty(value = "状态")
+    private String enabled;
+    private List<Timestamp> createTime;
+}
diff --git a/oying-system/src/main/java/com/oying/modules/system/mapper/MerchantsMapper.java b/oying-system/src/main/java/com/oying/modules/system/mapper/MerchantsMapper.java
new file mode 100644
index 0000000..c1ea786
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/mapper/MerchantsMapper.java
@@ -0,0 +1,22 @@
+package com.oying.modules.system.mapper;
+
+import com.oying.modules.system.domain.Merchants;
+import com.oying.modules.system.domain.dto.MerchantsQueryCriteria;
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Mapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+/**
+* @author lixin
+* @date 2025-05-29
+**/
+@Mapper
+public interface MerchantsMapper extends BaseMapper<Merchants> {
+
+    IPage<Merchants> findAll(@Param("criteria") MerchantsQueryCriteria criteria, Page<Object> page);
+
+    List<Merchants> findAll(@Param("criteria") MerchantsQueryCriteria criteria);
+}
diff --git a/oying-system/src/main/java/com/oying/modules/system/rest/MerchantsController.java b/oying-system/src/main/java/com/oying/modules/system/rest/MerchantsController.java
new file mode 100644
index 0000000..2ccf7ee
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/rest/MerchantsController.java
@@ -0,0 +1,73 @@
+package com.oying.modules.system.rest;
+
+import com.oying.annotation.Log;
+import com.oying.modules.system.domain.Merchants;
+import com.oying.modules.system.service.MerchantsService;
+import com.oying.modules.system.domain.dto.MerchantsQueryCriteria;
+import lombok.RequiredArgsConstructor;
+import java.util.List;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import io.swagger.annotations.*;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.oying.utils.PageResult;
+
+/**
+* @author lixin
+* @date 2025-05-29
+**/
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "商户信息")
+@RequestMapping("/api/merchants")
+public class MerchantsController {
+
+    private final MerchantsService merchantsService;
+
+    @ApiOperation("导出数据")
+    @GetMapping(value = "/download")
+    @PreAuthorize("@el.check('merchants:list')")
+    public void exportMerchants(HttpServletResponse response, MerchantsQueryCriteria criteria) throws IOException {
+        merchantsService.download(merchantsService.queryAll(criteria), response);
+    }
+
+    @GetMapping
+    @ApiOperation("查询商户信息")
+    @PreAuthorize("@el.check('merchants:list')")
+    public ResponseEntity<PageResult<Merchants>> queryMerchants(MerchantsQueryCriteria criteria){
+        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
+        return new ResponseEntity<>(merchantsService.queryAll(criteria,page),HttpStatus.OK);
+    }
+
+    @PostMapping
+    @Log("新增商户信息")
+    @ApiOperation("新增商户信息")
+    @PreAuthorize("@el.check('merchants:add')")
+    public ResponseEntity<Object> createMerchants(@Validated @RequestBody Merchants resources){
+        merchantsService.create(resources);
+        return new ResponseEntity<>(HttpStatus.CREATED);
+    }
+
+    @PutMapping
+    @Log("修改商户信息")
+    @ApiOperation("修改商户信息")
+    @PreAuthorize("@el.check('merchants:edit')")
+    public ResponseEntity<Object> updateMerchants(@Validated @RequestBody Merchants resources){
+        merchantsService.update(resources);
+        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+    }
+
+    @DeleteMapping
+    @Log("删除商户信息")
+    @ApiOperation("删除商户信息")
+    @PreAuthorize("@el.check('merchants:del')")
+    public ResponseEntity<Object> deleteMerchants(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
+        merchantsService.deleteAll(ids);
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
+}
diff --git a/oying-system/src/main/java/com/oying/modules/system/service/MerchantsService.java b/oying-system/src/main/java/com/oying/modules/system/service/MerchantsService.java
new file mode 100644
index 0000000..c822ba9
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/service/MerchantsService.java
@@ -0,0 +1,59 @@
+package com.oying.modules.system.service;
+
+import com.oying.modules.system.domain.Merchants;
+import com.oying.modules.system.domain.dto.MerchantsQueryCriteria;
+import java.util.List;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.oying.utils.PageResult;
+
+/**
+* @description 服务接口
+* @author lixin
+* @date 2025-05-29
+**/
+public interface MerchantsService extends IService<Merchants> {
+
+    /**
+    * 查询数据分页
+    * @param criteria 条件
+    * @param page 分页参数
+    * @return PageResult
+    */
+    PageResult<Merchants> queryAll(MerchantsQueryCriteria criteria, Page<Object> page);
+
+    /**
+    * 查询所有数据不分页
+    * @param criteria 条件参数
+    * @return List<MerchantsDto>
+    */
+    List<Merchants> queryAll(MerchantsQueryCriteria criteria);
+
+    /**
+    * 创建
+    * @param resources /
+    */
+    void create(Merchants resources);
+
+    /**
+    * 编辑
+    * @param resources /
+    */
+    void update(Merchants resources);
+
+    /**
+    * 多选删除
+    * @param ids /
+    */
+    void deleteAll(List<Long> ids);
+
+    /**
+    * 导出数据
+    * @param all 待导出的数据
+    * @param response /
+    * @throws IOException /
+    */
+    void download(List<Merchants> all, HttpServletResponse response) throws IOException;
+}
diff --git a/oying-system/src/main/java/com/oying/modules/system/service/impl/MerchantsServiceImpl.java b/oying-system/src/main/java/com/oying/modules/system/service/impl/MerchantsServiceImpl.java
new file mode 100644
index 0000000..ca6c22c
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/system/service/impl/MerchantsServiceImpl.java
@@ -0,0 +1,86 @@
+package com.oying.modules.system.service.impl;
+
+import com.oying.modules.system.domain.Merchants;
+import com.oying.utils.FileUtil;
+import lombok.RequiredArgsConstructor;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.oying.modules.system.service.MerchantsService;
+import com.oying.modules.system.domain.dto.MerchantsQueryCriteria;
+import com.oying.modules.system.mapper.MerchantsMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.oying.utils.PageUtil;
+import java.util.List;
+import java.util.Map;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import com.oying.utils.PageResult;
+
+/**
+* @description 服务实现
+* @author lixin
+* @date 2025-05-29
+**/
+@Service
+@RequiredArgsConstructor
+public class MerchantsServiceImpl extends ServiceImpl<MerchantsMapper, Merchants> implements MerchantsService {
+
+    private final MerchantsMapper merchantsMapper;
+
+    @Override
+    public PageResult<Merchants> queryAll(MerchantsQueryCriteria criteria, Page<Object> page){
+        return PageUtil.toPage(merchantsMapper.findAll(criteria, page));
+    }
+
+    @Override
+    public List<Merchants> queryAll(MerchantsQueryCriteria criteria){
+        return merchantsMapper.findAll(criteria);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void create(Merchants resources) {
+        merchantsMapper.insert(resources);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void update(Merchants resources) {
+        Merchants merchants = getById(resources.getMerchantsId());
+        merchants.copy(resources);
+        merchantsMapper.updateById(merchants);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteAll(List<Long> ids) {
+        merchantsMapper.deleteBatchIds(ids);
+    }
+
+    @Override
+    public void download(List<Merchants> all, HttpServletResponse response) throws IOException {
+        List<Map<String, Object>> list = new ArrayList<>();
+        for (Merchants merchants : all) {
+            Map<String, Object> map = new LinkedHashMap<>();
+            map.put("名称", merchants.getMerchantName());
+            map.put("商户编码", merchants.getMerchantCode());
+            map.put("营业执照号", merchants.getBusinessLicense());
+            map.put("营业执照号路径", merchants.getBusinessLicensePath());
+            map.put("联系手机", merchants.getContactMobile());
+            map.put("排序", merchants.getMerchantsSort());
+            map.put("状态", merchants.getEnabled());
+            map.put("审核人", merchants.getAuthUser());
+            map.put("审核时间", merchants.getAuthTime());
+            map.put("审核信息", merchants.getAuthMessage());
+            map.put("创建者", merchants.getCreateBy());
+            map.put("更新者", merchants.getUpdateBy());
+            map.put("创建日期", merchants.getCreateTime());
+            map.put("更新时间", merchants.getUpdateTime());
+            list.add(map);
+        }
+        FileUtil.downloadExcel(list, response);
+    }
+}
diff --git a/oying-system/src/main/resources/mapper/system/MerchantsMapper.xml b/oying-system/src/main/resources/mapper/system/MerchantsMapper.xml
new file mode 100644
index 0000000..526dea8
--- /dev/null
+++ b/oying-system/src/main/resources/mapper/system/MerchantsMapper.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.oying.modules.system.mapper.MerchantsMapper">
+    <resultMap id="BaseResultMap" type="com.oying.modules.system.domain.Merchants">
+        <id column="merchants_id" property="merchantsId"/>
+        <result column="merchant_name" property="merchantName"/>
+        <result column="merchant_code" property="merchantCode"/>
+        <result column="business_license" property="businessLicense"/>
+        <result column="business_license_path" property="businessLicensePath"/>
+        <result column="contact_mobile" property="contactMobile"/>
+        <result column="merchants_sort" property="merchantsSort"/>
+        <result column="enabled" property="enabled"/>
+        <result column="create_by" property="createBy"/>
+        <result column="update_by" property="updateBy"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="auth_user" property="authUser"/>
+        <result column="auth_time" property="authTime"/>
+        <result column="auth_message" property="authMessage"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        merchants_id, merchant_name, merchant_code, business_license, business_license_path, contact_mobile, merchants_sort, enabled, create_by, update_by, create_time, update_time, auth_user, auth_time, auth_message
+    </sql>
+
+    <select id="findAll" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from sys_merchants
+        <where>
+            <if test="criteria.blurry != null and criteria.blurry != ''">
+                and (
+                merchant_name like concat('%', #{criteria.blurry}, '%')
+                or merchant_code like concat('%', #{criteria.blurry}, '%')
+                or business_license like concat('%', #{criteria.blurry}, '%')
+                or contact_mobile like concat('%', #{criteria.blurry}, '%')
+                )
+            </if>
+            <if test="criteria.enabled != null">
+                and enabled = #{criteria.enabled}
+            </if>
+            <if test="criteria.createTime != null and criteria.createTime.size() > 0">
+                AND create_time BETWEEN #{criteria.createTime[0]} AND #{criteria.createTime[1]}
+            </if>
+        </where>
+        order by merchants_sort desc
+    </select>
+</mapper>

--
Gitblit v1.9.3