Ver código fonte

Merge remote-tracking branch 'gogs-epliboly/master'

Huanyi 1 mês atrás
pai
commit
8a4b805d01

+ 6 - 2
pom.xml

@@ -88,14 +88,18 @@
             <properties>
                 <!-- 环境标识,需要与配置文件的名称相对应 -->
                 <profiles.active>test</profiles.active>
-                <nacos.server>192.168.1.140:8848</nacos.server>
+                <nacos.server>127.0.0.1:8848</nacos.server>
                 <nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
                 <nacos.config.group>DEFAULT_GROUP</nacos.config.group>
                 <nacos.username>nacos</nacos.username>
                 <nacos.password>nacos</nacos.password>
                 <logstash.address>127.0.0.1:4560</logstash.address>
-                <discovery.ip>192.168.1.140</discovery.ip>
+                <discovery.ip>127.0.0.1</discovery.ip>
             </properties>
+            <activation>
+                <!-- 默认环境 -->
+                <activeByDefault>true</activeByDefault>
+            </activation>
         </profile>
         <profile>
             <id>prod</id>

+ 1 - 0
ruoyi-api/pom.xml

@@ -14,6 +14,7 @@
         <module>ruoyi-api-resource</module>
         <module>ruoyi-api-workflow</module>
         <module>yingpaipay-api-service</module>
+        <module>yingpaipay-api-fulfiller</module>
     </modules>
 
     <artifactId>ruoyi-api</artifactId>

+ 7 - 0
ruoyi-api/ruoyi-api-bom/pom.xml

@@ -47,6 +47,13 @@
                 <version>${revision}</version>
             </dependency>
 
+            <!-- 履约者服务接口 -->
+            <dependency>
+                <groupId>org.dromara</groupId>
+                <artifactId>yingpaipay-api-fulfiller</artifactId>
+                <version>${revision}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 </project>

+ 24 - 0
ruoyi-api/yingpaipay-api-fulfiller/pom.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.dromara</groupId>
+        <artifactId>ruoyi-api</artifactId>
+        <version>${revision}</version>
+    </parent>
+
+    <artifactId>yingpaipay-api-fulfiller</artifactId>
+
+    <dependencies>
+
+        <!-- RuoYi Common Core-->
+        <dependency>
+            <groupId>org.dromara</groupId>
+            <artifactId>ruoyi-common-core</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 31 - 0
ruoyi-api/yingpaipay-api-fulfiller/src/main/java/org/dromara/fulfiller/api/RemoteFulfillerService.java

@@ -0,0 +1,31 @@
+package org.dromara.fulfiller.api;
+
+import org.dromara.common.core.exception.user.UserException;
+import org.dromara.fulfiller.api.model.FulfillerLoginUser;
+
+/**
+ * 履约者服务接口
+ *
+ * @author steelwei
+ */
+public interface RemoteFulfillerService {
+
+    /**
+     * 根据手机号查询履约者登录信息
+     *
+     * @param phone 手机号
+     * @return 履约者登录信息
+     * @throws UserException 用户异常
+     */
+    FulfillerLoginUser getFulfillerByPhone(String phone) throws UserException;
+
+    /**
+     * 根据ID查询履约者登录信息
+     *
+     * @param id 履约者ID
+     * @return 履约者登录信息
+     * @throws UserException 用户异常
+     */
+    FulfillerLoginUser getFulfillerById(Long id) throws UserException;
+
+}

+ 49 - 0
ruoyi-api/yingpaipay-api-fulfiller/src/main/java/org/dromara/fulfiller/api/model/FulfillerLoginUser.java

@@ -0,0 +1,49 @@
+package org.dromara.fulfiller.api.model;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * 履约者登录用户信息
+ *
+ * @author steelwei
+ */
+@Data
+public class FulfillerLoginUser implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 履约者ID
+     */
+    private Long id;
+
+    /**
+     * 手机号
+     */
+    private String phone;
+
+    /**
+     * 密码(BCrypt加密)
+     */
+    private String password;
+
+    /**
+     * 姓名
+     */
+    private String name;
+
+    /**
+     * 状态 (resting:休息, busy:接单中, disabled:禁用)
+     */
+    private String status;
+
+    /**
+     * 租户ID
+     */
+    private String tenantId;
+
+}

+ 12 - 0
ruoyi-auth/pom.xml

@@ -87,6 +87,18 @@
             <artifactId>ruoyi-api-resource</artifactId>
         </dependency>
 
+        <!-- YingPaiPay Api Service -->
+        <dependency>
+            <groupId>org.dromara</groupId>
+            <artifactId>yingpaipay-api-service</artifactId>
+        </dependency>
+
+        <!-- YingPaiPay Api Fulfiller -->
+        <dependency>
+            <groupId>org.dromara</groupId>
+            <artifactId>yingpaipay-api-fulfiller</artifactId>
+        </dependency>
+
         <!-- 自定义负载均衡(多团队开发使用) -->
 <!--        <dependency>-->
 <!--            <groupId>org.dromara</groupId>-->

+ 14 - 4
ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java

@@ -20,6 +20,7 @@ import org.dromara.auth.form.SocialLoginBody;
 import org.dromara.auth.service.IAuthStrategy;
 import org.dromara.auth.service.SysLoginService;
 import org.dromara.common.core.constant.SystemConstants;
+import org.dromara.common.core.enums.UserType;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.domain.model.LoginBody;
 import org.dromara.common.core.utils.*;
@@ -39,6 +40,7 @@ import org.dromara.system.api.RemoteSocialService;
 import org.dromara.system.api.RemoteTenantService;
 import org.dromara.system.api.domain.vo.RemoteClientVo;
 import org.dromara.system.api.domain.vo.RemoteTenantVo;
+import org.dromara.system.api.model.LoginUser;
 import org.springframework.web.bind.annotation.*;
 
 import java.net.URL;
@@ -103,10 +105,18 @@ public class TokenController {
         // 登录
         LoginVo loginVo = IAuthStrategy.login(body, clientVo, grantType);
 
-        Long userId = LoginHelper.getUserId();
-        scheduledExecutorService.schedule(() -> {
-            remoteMessageService.publishMessage(List.of(userId), DateUtils.getTodayHour(new Date()) + "好,欢迎登录 一站护萌 后台管理系统");
-        }, 5, TimeUnit.SECONDS);
+        // 仅后台系统用户发送欢迎消息,履约者等其他用户类型跳过 @author steelwei
+        try {
+            LoginUser currentUser = LoginHelper.getLoginUser();
+            if (currentUser != null && UserType.SYS_USER.getUserType().equals(currentUser.getUserType())) {
+                Long userId = LoginHelper.getUserId();
+                scheduledExecutorService.schedule(() -> {
+                    remoteMessageService.publishMessage(List.of(userId), DateUtils.getTodayHour(new Date()) + "好,欢迎登录 一站护萌 后台管理系统");
+                }, 5, TimeUnit.SECONDS);
+            }
+        } catch (Exception e) {
+            log.warn("发送登录欢迎消息失败: {}", e.getMessage());
+        }
         return R.ok(loginVo);
     }
 

+ 99 - 0
ruoyi-auth/src/main/java/org/dromara/auth/service/impl/FulfillerPasswordAuthStrategy.java

@@ -0,0 +1,99 @@
+package org.dromara.auth.service.impl;
+
+import cn.dev33.satoken.stp.StpUtil;
+import cn.dev33.satoken.stp.parameter.SaLoginParameter;
+import cn.hutool.crypto.digest.BCrypt;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.auth.domain.vo.LoginVo;
+import org.dromara.auth.form.PasswordLoginBody;
+import org.dromara.auth.properties.CaptchaProperties;
+import org.dromara.auth.service.IAuthStrategy;
+import org.dromara.auth.service.SysLoginService;
+import org.dromara.common.core.constant.Constants;
+import org.dromara.common.core.enums.LoginType;
+import org.dromara.common.core.enums.UserType;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.core.utils.ValidatorUtils;
+import org.dromara.common.json.utils.JsonUtils;
+import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.common.tenant.helper.TenantHelper;
+import org.dromara.fulfiller.api.RemoteFulfillerService;
+import org.dromara.fulfiller.api.model.FulfillerLoginUser;
+import org.dromara.system.api.domain.vo.RemoteClientVo;
+import org.dromara.system.api.model.LoginUser;
+import org.springframework.stereotype.Service;
+
+/**
+ * 履约者密码认证策略
+ *
+ * @author steelwei
+ */
+@Slf4j
+@Service("fulfiller_password" + IAuthStrategy.BASE_NAME)
+@RequiredArgsConstructor
+public class FulfillerPasswordAuthStrategy implements IAuthStrategy {
+
+    private final CaptchaProperties captchaProperties;
+    private final SysLoginService loginService;
+
+    @DubboReference
+    private RemoteFulfillerService remoteFulfillerService;
+
+    @Override
+    public LoginVo login(String body, RemoteClientVo client) {
+        PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
+        ValidatorUtils.validate(loginBody);
+        String tenantId = loginBody.getTenantId();
+        String username = loginBody.getUsername();
+        String password = loginBody.getPassword();
+        String code = loginBody.getCode();
+        String uuid = loginBody.getUuid();
+
+        // 验证码开关
+        if (captchaProperties.getEnabled()) {
+            loginService.validateCaptcha(tenantId, username, code, uuid);
+        }
+
+        // 查询履约者信息并验证密码
+        LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
+            FulfillerLoginUser fulfiller = remoteFulfillerService.getFulfillerByPhone(username);
+            loginService.checkLogin(LoginType.PASSWORD, fulfiller.getTenantId(), username, 
+                () -> !BCrypt.checkpw(password, fulfiller.getPassword()));
+            
+            // 构建 LoginUser 对象
+            LoginUser user = new LoginUser();
+            user.setTenantId(fulfiller.getTenantId());
+            user.setUserId(fulfiller.getId()); // 使用 flf_fulfiller.id
+            user.setUsername(fulfiller.getPhone());
+            user.setNickname(fulfiller.getName());
+            user.setPassword(fulfiller.getPassword());
+            user.setUserType(UserType.FULFILLER_USER.getUserType());
+            return user;
+        });
+
+        loginUser.setClientKey(client.getClientKey());
+        loginUser.setDeviceType(client.getDeviceType());
+        
+        SaLoginParameter model = new SaLoginParameter();
+        model.setDeviceType(client.getDeviceType());
+        model.setTimeout(client.getTimeout());
+        model.setActiveTimeout(client.getActiveTimeout());
+        model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
+        
+        // 生成token
+        LoginHelper.login(loginUser, model);
+
+        LoginVo loginVo = new LoginVo();
+        loginVo.setAccessToken(StpUtil.getTokenValue());
+        loginVo.setExpireIn(StpUtil.getTokenTimeout());
+        loginVo.setClientId(client.getClientId());
+        
+        // 记录登录成功日志
+        loginService.recordLogininfor(tenantId, username, Constants.LOGIN_SUCCESS, "登录成功");
+        
+        return loginVo;
+    }
+
+}

+ 111 - 0
ruoyi-auth/src/main/java/org/dromara/auth/service/impl/FulfillerSmsAuthStrategy.java

@@ -0,0 +1,111 @@
+package org.dromara.auth.service.impl;
+
+import cn.dev33.satoken.stp.StpUtil;
+import cn.dev33.satoken.stp.parameter.SaLoginParameter;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.auth.domain.vo.LoginVo;
+import org.dromara.auth.form.SmsLoginBody;
+import org.dromara.auth.service.IAuthStrategy;
+import org.dromara.auth.service.SysLoginService;
+import org.dromara.common.core.constant.Constants;
+import org.dromara.common.core.constant.GlobalConstants;
+import org.dromara.common.core.enums.UserType;
+import org.dromara.common.core.exception.user.CaptchaExpireException;
+import org.dromara.common.core.utils.MessageUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.core.utils.ValidatorUtils;
+import org.dromara.common.json.utils.JsonUtils;
+import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.common.tenant.helper.TenantHelper;
+import org.dromara.fulfiller.api.RemoteFulfillerService;
+import org.dromara.fulfiller.api.model.FulfillerLoginUser;
+import org.dromara.system.api.domain.vo.RemoteClientVo;
+import org.dromara.system.api.model.LoginUser;
+import org.springframework.stereotype.Service;
+
+/**
+ * 履约者短信验证码认证策略
+ *
+ * @author steelwei
+ */
+@Slf4j
+@Service("fulfiller_sms" + IAuthStrategy.BASE_NAME)
+@RequiredArgsConstructor
+public class FulfillerSmsAuthStrategy implements IAuthStrategy {
+
+    private final SysLoginService loginService;
+
+    @DubboReference
+    private RemoteFulfillerService remoteFulfillerService;
+
+    @Override
+    public LoginVo login(String body, RemoteClientVo client) {
+        SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
+        ValidatorUtils.validate(loginBody);
+        String tenantId = loginBody.getTenantId();
+        String phonenumber = loginBody.getPhonenumber();
+        String smsCode = loginBody.getSmsCode();
+
+        // 验证短信验证码
+        validateSmsCode(tenantId, phonenumber, smsCode);
+
+        // 查询履约者信息
+        LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
+            FulfillerLoginUser fulfiller = remoteFulfillerService.getFulfillerByPhone(phonenumber);
+            
+            // 构建 LoginUser 对象
+            LoginUser user = new LoginUser();
+            user.setTenantId(fulfiller.getTenantId());
+            user.setUserId(fulfiller.getId()); // 使用 flf_fulfiller.id
+            user.setUsername(fulfiller.getPhone());
+            user.setNickname(fulfiller.getName());
+            user.setPassword(fulfiller.getPassword());
+            user.setUserType(UserType.FULFILLER_USER.getUserType());
+            return user;
+        });
+
+        loginUser.setClientKey(client.getClientKey());
+        loginUser.setDeviceType(client.getDeviceType());
+        
+        SaLoginParameter model = new SaLoginParameter();
+        model.setDeviceType(client.getDeviceType());
+        model.setTimeout(client.getTimeout());
+        model.setActiveTimeout(client.getActiveTimeout());
+        model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
+        
+        // 生成token
+        LoginHelper.login(loginUser, model);
+
+        LoginVo loginVo = new LoginVo();
+        loginVo.setAccessToken(StpUtil.getTokenValue());
+        loginVo.setExpireIn(StpUtil.getTokenTimeout());
+        loginVo.setClientId(client.getClientId());
+        
+        // 记录登录成功日志
+        loginService.recordLogininfor(tenantId, phonenumber, Constants.LOGIN_SUCCESS, "登录成功");
+        
+        return loginVo;
+    }
+
+    /**
+     * 校验短信验证码
+     */
+    private void validateSmsCode(String tenantId, String phonenumber, String smsCode) {
+        String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
+        if (StringUtils.isBlank(code)) {
+            loginService.recordLogininfor(tenantId, phonenumber, Constants.LOGIN_FAIL, 
+                MessageUtils.message("user.jcaptcha.expire"));
+            throw new CaptchaExpireException();
+        }
+        RedisUtils.deleteObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
+        if (!code.equals(smsCode)) {
+            loginService.recordLogininfor(tenantId, phonenumber, Constants.LOGIN_FAIL, 
+                MessageUtils.message("user.jcaptcha.error"));
+            throw new CaptchaExpireException();
+        }
+    }
+
+}

+ 6 - 0
ruoyi-modules/yingpaipay-archieves/src/main/java/org/dromara/archieves/service/impl/UsrPetServiceImpl.java

@@ -22,6 +22,7 @@ import org.dromara.archieves.mapper.UsrPetMapper;
 import org.dromara.archieves.mapper.UsrCustomerMapper;
 import org.dromara.archieves.mapper.SysTagRelMapper;
 import org.dromara.archieves.mapper.SysTagMapper;
+import org.dromara.archieves.service.IArcChangeLogService;
 import org.dromara.archieves.service.IUsrPetService;
 
 import java.util.List;
@@ -44,6 +45,7 @@ public class UsrPetServiceImpl implements IUsrPetService {
     private final UsrCustomerMapper customerMapper;
     private final SysTagRelMapper tagRelMapper;
     private final SysTagMapper tagMapper;
+    private final IArcChangeLogService arcChangeLogService;
 
     @Override
     public UsrPetVo queryById(Long id) {
@@ -125,6 +127,10 @@ public class UsrPetServiceImpl implements IUsrPetService {
         boolean flag = baseMapper.updateById(update) > 0;
         if (flag) {
             saveTagRels(bo.getId(), bo.getTagIds(), "pet");
+            // 如果有备注内容,记录变更日志
+            if (StringUtils.isNotBlank(bo.getRemark())) {
+                arcChangeLogService.addLog(bo.getId(), "pet", "备注", bo.getRemark());
+            }
         }
         return flag;
     }

+ 12 - 0
ruoyi-modules/yingpaipay-fulfiller/pom.xml

@@ -100,6 +100,18 @@
             <groupId>org.dromara</groupId>
             <artifactId>ruoyi-api-workflow</artifactId>
         </dependency>
+
+        <!-- YingPaiPay Api Service -->
+        <dependency>
+            <groupId>org.dromara</groupId>
+            <artifactId>yingpaipay-api-service</artifactId>
+        </dependency>
+
+        <!-- YingPaiPay Api Fulfiller -->
+        <dependency>
+            <groupId>org.dromara</groupId>
+            <artifactId>yingpaipay-api-fulfiller</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcprov-jdk18on</artifactId>

+ 2 - 0
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/YingpaipayFulfillerApplication.java

@@ -1,10 +1,12 @@
 package org.dromara.fulfiller;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
 
+@EnableDubbo
 @SpringBootApplication
 @Slf4j
 public class YingpaipayFulfillerApplication {

+ 81 - 0
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/dubbo/RemoteFulfillerServiceImpl.java

@@ -0,0 +1,81 @@
+package org.dromara.fulfiller.dubbo;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.dromara.common.core.exception.ServiceException;
+import org.dromara.common.core.exception.user.UserException;
+import org.dromara.common.tenant.helper.TenantHelper;
+import org.dromara.fulfiller.api.RemoteFulfillerService;
+import org.dromara.fulfiller.api.model.FulfillerLoginUser;
+import org.dromara.fulfiller.domain.FlfFulfiller;
+import org.dromara.fulfiller.mapper.FlfFulfillerMapper;
+import org.springframework.stereotype.Service;
+
+/**
+ * 履约者服务实现
+ *
+ * @author steelwei
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+@DubboService
+public class RemoteFulfillerServiceImpl implements RemoteFulfillerService {
+
+    private final FlfFulfillerMapper fulfillerMapper;
+
+    @Override
+    public FulfillerLoginUser getFulfillerByPhone(String phone) throws UserException {
+        FlfFulfiller fulfiller = fulfillerMapper.selectOne(
+            new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<FlfFulfiller>()
+                .eq(FlfFulfiller::getPhone, phone)
+                .eq(FlfFulfiller::getDelFlag, "0")
+        );
+        
+        if (fulfiller == null) {
+            log.info("登录用户:{} 不存在.", phone);
+            throw new UserException("user.not.exists");
+        }
+        
+        if ("disabled".equals(fulfiller.getStatus())) {
+            log.info("登录用户:{} 已被禁用.", phone);
+            throw new UserException("user.blocked");
+        }
+
+        return toLoginUser(fulfiller);
+    }
+
+    @Override
+    public FulfillerLoginUser getFulfillerById(Long id) throws UserException {
+        FlfFulfiller fulfiller = fulfillerMapper.selectById(id);
+        
+        if (fulfiller == null) {
+            log.info("履约者ID:{} 不存在.", id);
+            throw new UserException("user.not.exists");
+        }
+        
+        if ("disabled".equals(fulfiller.getStatus())) {
+            log.info("履约者ID:{} 已被禁用.", id);
+            throw new UserException("user.blocked");
+        }
+
+        return toLoginUser(fulfiller);
+    }
+
+    /**
+     * 手动转换 FlfFulfiller → FulfillerLoginUser(避免跨模块 MapStruct 转换器缺失)
+     */
+    private FulfillerLoginUser toLoginUser(FlfFulfiller fulfiller) {
+        FulfillerLoginUser loginUser = new FulfillerLoginUser();
+        loginUser.setId(fulfiller.getId());
+        loginUser.setPhone(fulfiller.getPhone());
+        loginUser.setPassword(fulfiller.getPassword());
+        loginUser.setName(fulfiller.getName());
+        loginUser.setStatus(fulfiller.getStatus());
+        loginUser.setTenantId(TenantHelper.getTenantId());
+        return loginUser;
+    }
+
+}
+

+ 32 - 0
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/enums/AuditTypeEnum.java

@@ -0,0 +1,32 @@
+package org.dromara.fulfiller.enums;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 审核类型枚举
+ *
+ * @author steelwei
+ */
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum AuditTypeEnum {
+
+    /** 入驻审核 */
+    REGISTER("register", "入驻审核"),
+
+    /** 资质变更审核 */
+    QUALIFICATION("qualification", "资质变更审核");
+
+    private final String code;
+    private final String label;
+
+    public static List<AuditTypeEnum> list() {
+        return Arrays.asList(values());
+    }
+
+}

+ 14 - 33
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/service/impl/FlfAuditServiceImpl.java

@@ -1,13 +1,11 @@
 package org.dromara.fulfiller.service.impl;
 
-import org.dromara.common.core.enums.UserType;
+import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.PageQuery;
-import org.dromara.common.platform.Platform;
 import org.dromara.common.satoken.utils.LoginHelper;
-import org.dromara.common.tenant.helper.TenantHelper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -20,14 +18,13 @@ import org.dromara.fulfiller.domain.FlfAudit;
 import org.dromara.fulfiller.domain.FlfFulfiller;
 import org.dromara.fulfiller.domain.bo.FlfAuditBo;
 import org.dromara.fulfiller.domain.vo.FlfAuditVo;
+import org.dromara.fulfiller.enums.AuditTypeEnum;
 import org.dromara.fulfiller.mapper.FlfAuditMapper;
 import org.dromara.fulfiller.mapper.FlfFulfillerMapper;
 import org.dromara.fulfiller.service.IFlfAuditService;
 import org.dromara.resource.api.RemoteFileService;
 import org.dromara.resource.api.domain.RemoteFile;
 import org.dromara.system.api.RemoteAreaStationService;
-import org.dromara.system.api.RemoteUserService;
-import org.dromara.system.api.domain.bo.RemoteUserBo;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -47,9 +44,6 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
     private final FlfAuditMapper baseMapper;
     private final FlfFulfillerMapper fulfillerMapper;
 
-    @DubboReference
-    private RemoteUserService remoteUserService;
-
     @DubboReference
     private RemoteFileService remoteFileService;
 
@@ -159,10 +153,10 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
     public Boolean pass(Long id) {
         FlfAudit audit = baseMapper.selectById(id);
         if (audit == null) {
-            throw new RuntimeException("审核记录不存在");
+            throw new ServiceException("审核记录不存在");
         }
         if (audit.getStatus() != 0) {
-            throw new RuntimeException("该记录已处理,不可重复操作");
+            throw new ServiceException("该记录已处理,不可重复操作");
         }
 
         // 更新审核状态
@@ -173,8 +167,8 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
         update.setAuditTime(new Date());
         baseMapper.updateById(update);
 
-        // 创建或更新履约者信息
-        if ("register".equals(audit.getType()) && audit.getFulfillerId() != null) {
+        // 创建或更新履约者信息 @author steelwei
+        if (AuditTypeEnum.REGISTER.getCode().equals(audit.getType()) && audit.getFulfillerId() != null) {
             // 已有履约者的修改认证重新审核:直接更新履约者信息
             FlfFulfiller fulfiller = fulfillerMapper.selectById(audit.getFulfillerId());
             if (fulfiller != null) {
@@ -186,24 +180,11 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
                 fulfiller.setAuthQual(StringUtils.isNotBlank(audit.getQualifications()));
                 fulfillerMapper.updateById(fulfiller);
             }
-        } else if ("register".equals(audit.getType())) {
-            // 首次入驻审核通过:创建用户和履约者
-            // 1. 创建 sys_user 记录(platformId=FULFILLER, userType=fulfiller_user)
-            RemoteUserBo userBo = new RemoteUserBo();
-            userBo.setUserName(audit.getPhone());
-            userBo.setNickName(audit.getName());
-            userBo.setPassword(audit.getPassword());
-            userBo.setPhonenumber(audit.getPhone());
-            userBo.setSex(audit.getGender());
-            userBo.setUserType(UserType.FULFILLER_USER.getUserType());
-            userBo.setPlatformId(Platform.FULFILLER.getId());
-            userBo.setStatus("0");
-            userBo.setTenantId(TenantHelper.getTenantId());
-            Long sysUserId = remoteUserService.createUser(userBo);
-
-            // 2. 创建 flf_fulfiller 记录
+        } else if (AuditTypeEnum.REGISTER.getCode().equals(audit.getType())) {
+            // 首次入驻审核通过:创建履约者 @author steelwei
+            // 创建 flf_fulfiller 记录(不再创建 sys_user)
             FlfFulfiller fulfiller = new FlfFulfiller();
-            fulfiller.setUserId(sysUserId);
+            fulfiller.setUserId(null); // 不再关联 sys_user
             fulfiller.setName(audit.getName());
             fulfiller.setRealName(audit.getRealName());
             fulfiller.setPhone(audit.getPhone());
@@ -227,12 +208,12 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
             fulfiller.setRejectCount(0);
             fulfillerMapper.insert(fulfiller);
 
-            // 3. 回写fulfillerId到审核记录
+            // 回写fulfillerId到审核记录
             FlfAudit auditUpdate2 = new FlfAudit();
             auditUpdate2.setId(id);
             auditUpdate2.setFulfillerId(fulfiller.getId());
             baseMapper.updateById(auditUpdate2);
-        } else if ("qualification".equals(audit.getType())) {
+        } else if (AuditTypeEnum.QUALIFICATION.getCode().equals(audit.getType())) {
             // 资质变更审核通过:更新现有履约者的认证信息
             FlfFulfiller fulfiller = fulfillerMapper.selectById(audit.getFulfillerId());
             if (fulfiller != null) {
@@ -253,10 +234,10 @@ public class FlfAuditServiceImpl implements IFlfAuditService {
     public Boolean reject(Long id, String rejectReason) {
         FlfAudit audit = baseMapper.selectById(id);
         if (audit == null) {
-            throw new RuntimeException("审核记录不存在");
+            throw new ServiceException("审核记录不存在");
         }
         if (audit.getStatus() != 0) {
-            throw new RuntimeException("该记录已处理,不可重复操作");
+            throw new ServiceException("该记录已处理,不可重复操作");
         }
 
         FlfAudit update = new FlfAudit();

+ 39 - 70
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/service/impl/FlfFulfillerServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.fulfiller.service.impl;
 
+import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -11,12 +12,7 @@ import cn.hutool.crypto.digest.BCrypt;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
-import org.dromara.common.core.enums.UserType;
-import org.dromara.common.platform.Platform;
 import org.dromara.common.satoken.utils.LoginHelper;
-import org.dromara.common.tenant.helper.TenantHelper;
-import org.dromara.system.api.RemoteUserService;
-import org.dromara.system.api.domain.bo.RemoteUserBo;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.dromara.fulfiller.domain.FlfAudit;
@@ -70,14 +66,11 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     private final SysTagRelMapper tagRelMapper;
 
     @DubboReference
-    private RemoteUserService remoteUserService;
+    private RemoteAreaStationService remoteAreaStationService;
 
     @DubboReference
     private RemoteFileService remoteFileService;
 
-    @DubboReference
-    private RemoteAreaStationService remoteAreaStationService;
-
     @Override
     public FlfFulfillerVo queryById(Long id) {
         FlfFulfillerVo vo = baseMapper.selectVoById(id);
@@ -128,26 +121,14 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean insertByBo(FlfFulfillerBo bo) {
-        // 1. 先创建 sys_user 账号(用于App登录)
-        RemoteUserBo userBo = new RemoteUserBo();
-        userBo.setUserName(bo.getPhone());
-        userBo.setNickName(bo.getName());
+        // 创建 flf_fulfiller 记录(不再创建 sys_user) @author steelwei
         // 密码需要BCrypt加密
-        String encryptedPwd = StringUtils.isNotBlank(bo.getPassword()) 
-            ? BCrypt.hashpw(bo.getPassword()) 
+        String encryptedPwd = StringUtils.isNotBlank(bo.getPassword())
+            ? BCrypt.hashpw(bo.getPassword())
             : BCrypt.hashpw("123456"); // 默认密码
-        userBo.setPassword(encryptedPwd);
-        userBo.setPhonenumber(bo.getPhone());
-        userBo.setSex(bo.getGender());
-        userBo.setUserType(UserType.FULFILLER_USER.getUserType());
-        userBo.setPlatformId(Platform.FULFILLER.getId());
-        userBo.setStatus("0");
-        userBo.setTenantId(TenantHelper.getTenantId());
-        Long sysUserId = remoteUserService.createUser(userBo);
-
-        // 2. 创建 flf_fulfiller 记录并关联 userId
+
         FlfFulfiller add = MapstructUtils.convert(bo, FlfFulfiller.class);
-        add.setUserId(sysUserId);
+        add.setUserId(null); // 不再关联 sys_user
         add.setPassword(encryptedPwd);
         validEntityBeforeSave(add);
         boolean flag = baseMapper.insert(add) > 0;
@@ -182,7 +163,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     public Boolean resetPwd(Long id, String password) {
         FlfFulfiller fulfiller = baseMapper.selectById(id);
         if (fulfiller == null) {
-            throw new RuntimeException("履约者不存在");
+            throw new ServiceException("履约者不存在");
         }
         String encryptedPwd = BCrypt.hashpw(password);
         // 更新 flf_fulfiller 表密码
@@ -190,10 +171,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
         update.setId(id);
         update.setPassword(encryptedPwd);
         baseMapper.updateById(update);
-        // 同步更新 sys_user 表密码
-        if (fulfiller.getUserId() != null) {
-            remoteUserService.resetUserPwd(fulfiller.getUserId(), encryptedPwd);
-        }
+        // 不再同步更新 sys_user 表密码 @author steelwei
         return true;
     }
 
@@ -202,7 +180,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     public Boolean reward(FlfRewardBo bo) {
         FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
         if (fulfiller == null) {
-            throw new RuntimeException("履约者不存在");
+            throw new ServiceException("履约者不存在");
         }
 
         int delta = "punish".equals(bo.getType()) ? -bo.getAmount() : bo.getAmount();
@@ -262,7 +240,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     public Boolean adjustPoints(FlfAdjustPointsBo bo) {
         FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
         if (fulfiller == null) {
-            throw new RuntimeException("履约者不存在");
+            throw new ServiceException("履约者不存在");
         }
 
         int newPoints = fulfiller.getPoints() + bo.getAmount();
@@ -289,7 +267,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     public Boolean adjustBalance(FlfAdjustBalanceBo bo) {
         FlfFulfiller fulfiller = baseMapper.selectById(bo.getFulfillerId());
         if (fulfiller == null) {
-            throw new RuntimeException("履约者不存在");
+            throw new ServiceException("履约者不存在");
         }
 
         long newBalance = fulfiller.getBalance() + bo.getAmount();
@@ -324,9 +302,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public FlfFulfillerVo queryByUserId(Long userId) {
-        FlfFulfillerVo vo = baseMapper.selectVoOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfillerVo vo = baseMapper.selectVoById(userId);
         if (vo != null) {
             vo.setTags(queryTagsByTargetId(vo.getId(), "fulfiller"));
             enrichVo(vo);
@@ -449,9 +426,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updateAvatarByUserId(Long userId, String avatar) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -461,9 +437,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updateNameByUserId(Long userId, String name) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -473,9 +448,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updateStatusByUserId(Long userId, String status) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -485,9 +459,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updateCityByUserId(Long userId, String cityCode, String cityName) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -498,9 +471,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updatePhoneByUserId(Long userId, String phone) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -511,7 +483,7 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
                 .ne(FlfFulfiller::getId, fulfiller.getId())
         );
         if (count > 0) {
-            throw new RuntimeException("该手机号已被使用");
+            throw new ServiceException("该手机号已被使用");
         }
         fulfiller.setPhone(phone);
         return baseMapper.updateById(fulfiller) > 0;
@@ -519,15 +491,14 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
 
     @Override
     public Boolean updatePasswordByUserId(Long userId, String oldPassword, String newPassword) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
         // 验证旧密码
         if (!BCrypt.checkpw(oldPassword, fulfiller.getPassword())) {
-            throw new RuntimeException("原密码错误");
+            throw new ServiceException("原密码错误");
         }
         // 加密新密码
         String hashedPassword = BCrypt.hashpw(newPassword);
@@ -538,9 +509,8 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean deleteAccountByUserId(Long userId) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
@@ -551,13 +521,12 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean updateAuthInfoByUserId(Long userId, java.util.Map<String, String> params) {
-        FlfFulfiller fulfiller = baseMapper.selectOne(
-            Wrappers.lambdaQuery(FlfFulfiller.class).eq(FlfFulfiller::getUserId, userId)
-        );
+        // userId 现在是 flf_fulfiller.id @author steelwei
+        FlfFulfiller fulfiller = baseMapper.selectById(userId);
         if (fulfiller == null) {
             return false;
         }
-        
+
         // 检查是否已有待审核记录,避免重复提交
         Long pendingCount = auditMapper.selectCount(
             Wrappers.lambdaQuery(FlfAudit.class)
@@ -565,9 +534,9 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
                 .eq(FlfAudit::getStatus, 0)
         );
         if (pendingCount > 0) {
-            throw new RuntimeException("您的认证信息正在审核中,请等待审核完成后再修改");
+            throw new ServiceException("您的认证信息正在审核中,请等待审核完成后再修改");
         }
-        
+
         // 查找该履约者已有的审核记录(取最新一条)
         FlfAudit audit = auditMapper.selectOne(
             Wrappers.lambdaQuery(FlfAudit.class)
@@ -575,11 +544,11 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
                 .orderByDesc(FlfAudit::getCreateTime)
                 .last("LIMIT 1")
         );
-        
+
         if (audit == null) {
             return false;
         }
-        
+
         // 在原有审核记录上更新信息和状态
         if (params.containsKey("idCardFront")) {
             audit.setIdCardFront(Long.parseLong(params.get("idCardFront")));
@@ -593,13 +562,13 @@ public class FlfFulfillerServiceImpl implements IFlfFulfillerService {
         if (params.containsKey("qualifications")) {
             audit.setQualifications(params.get("qualifications"));
         }
-        
+
         // 重置为待审核状态
         audit.setStatus(0);
         audit.setRejectReason(null);
         audit.setAuditBy(null);
         audit.setAuditTime(null);
-        
+
         return auditMapper.updateById(audit) > 0;
     }