2 Incheckningar 14002442c1 ... 177f6faa33

Upphovsman SHA1 Meddelande Datum
  limingming 177f6faa33 后台 商户相关信息优化 1 år sedan
  limingming 4dc21a2829 后台 商户相关信息的增删改查 1 år sedan

+ 56 - 9
ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/MerchantUserController.java

@@ -1,19 +1,27 @@
 package com.ruoyi.web.controller.platform;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.utils.CreateCharAndNum;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.system.domain.BaseParam;
 import com.ruoyi.system.domain.MerchantUser;
 import com.ruoyi.system.service.MerchantUserService;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
-import java.util.UUID;
 
 /**
  * 商户信息Controller
- * 
+ *
  * @author liming
  * @date 2023-08-16
  */
@@ -22,9 +30,22 @@ import java.util.UUID;
 public class MerchantUserController extends BaseController {
     @Autowired
     private MerchantUserService merchantUserService;
+    @Autowired
+    private CreateCharAndNum createCharAndNum;
+
+    /**
+     * 查询商户列表
+     */
+    @PostMapping("/list")
+    public R<IPage<MerchantUser>> list(@RequestBody BaseParam param) {
+        IPage<MerchantUser> merchantUserIPage = merchantUserService.page(new Page<MerchantUser>().setCurrent(param.getCurrent()).setSize(param.getSize()),
+                new LambdaQueryWrapper<MerchantUser>().like(param.getName() != null, MerchantUser::getName, param.getName())
+                        .eq(MerchantUser::getDelFlag, 0));
+        return R.ok(merchantUserIPage);
+    }
 
     /**
-     * 查询商户信息列表
+     * 查询全部商户信息列表
      */
     @PostMapping("/allList")
     public R<List<MerchantUser>> list() {
@@ -36,18 +57,44 @@ public class MerchantUserController extends BaseController {
     /**
      * 新增商户信息
      */
-    @PostMapping("/add")
+    @PostMapping("/addOrUpdate")
     public R<Boolean> add(@RequestBody MerchantUser param) {
         if (param.getId() != null) {
+            //更新
             param.setUpdateTime(DateUtils.getNowDate());
-        }else {
+        } else {
+            //新增
             param.setCreateTime(DateUtils.getNowDate());
-            //随机生成6位商户标识
-            String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 6);
-            param.setMerchantCode(uuid);
+//            //随机生成6位商户标识
+//            String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 6);
+            //随机生成4位数字加字母
+            String charAndNum = createCharAndNum.getCharAndNum(4);
+            //如果有重复的重新生成
+            for (int i = 0; i < 10; i++) {
+                MerchantUser one = merchantUserService.getOne(new LambdaQueryWrapper<MerchantUser>().eq(MerchantUser::getMerchantCode, charAndNum), false);
+                if (one != null) {
+                    charAndNum = createCharAndNum.getCharAndNum(4);
+                    continue;
+                }
+                break;
+            }
+            param.setMerchantCode(charAndNum);
         }
         return R.ok(merchantUserService.saveOrUpdate(param));
 
     }
 
+
+    /**
+     * 删除商户
+     */
+    @PostMapping("/delete")
+    public R<T> remove(@RequestBody BaseParam param) {
+        boolean flat = merchantUserService.removeById(param.getId());
+        if (!flat) {
+            return R.fail("删除失败");
+        }
+        return R.ok();
+    }
+
 }

+ 30 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/CreateCharAndNum.java

@@ -0,0 +1,30 @@
+package com.ruoyi.common.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.util.Random;
+
+/**
+ * @Author: LiMingMing
+ * @Date: 2023/8/23 22:23
+ * @Description: TODO
+ **/
+@Component
+public class CreateCharAndNum {
+    public String getCharAndNum(int length) {
+        StringBuilder valSb = new StringBuilder();
+        Random random = new Random();
+        for (int i = 0; i < length; i++) {
+            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
+            if ("char".equalsIgnoreCase(charOrNum)) {
+                // 字符串
+                int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;  // 取得大写字母还是小写字母
+                valSb.append((char) (choice + random.nextInt(26)));
+            } else {
+                // 数字
+                valSb.append(String.valueOf(random.nextInt(10)));
+            }
+        }
+        return valSb.toString();
+    }
+}

+ 16 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/MerchantUser.java

@@ -29,10 +29,26 @@ public class MerchantUser implements Serializable {
     @Excel(name = "商户名称")
     private String name;
 
+    /** 商户缩写 */
+    @Excel(name = "商户缩写")
+    private String merchantAbb;
+
     /** 商户标识码 */
     @Excel(name = "商户标识码")
     private String merchantCode;
 
+    /** 联系人 */
+    @Excel(name = "联系人")
+    private String user;
+
+    /** 手机号 */
+    @Excel(name = "手机号")
+    private String phone;
+
+    /** 地址 */
+    @Excel(name = "地址")
+    private String address;
+
     /** 状态(0使用中 1未使用) */
     @Excel(name = "状态", readConverterExp = "0=使用中,1=未使用")
     private String status;