|  | @@ -1,40 +1,36 @@
 | 
	
		
			
				|  |  |  package com.ruoyi.system.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.io.IOException;
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | -import com.ruoyi.common.core.domain.model.LoginBody;
 | 
	
		
			
				|  |  | -import com.ruoyi.common.core.domain.model.LoginUser;
 | 
	
		
			
				|  |  | -import okhttp3.OkHttpClient;
 | 
	
		
			
				|  |  | -import okhttp3.Request;
 | 
	
		
			
				|  |  | -import okhttp3.Response;
 | 
	
		
			
				|  |  | -import org.slf4j.Logger;
 | 
	
		
			
				|  |  | -import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | -import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | -import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | -import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.annotation.DataScope;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.constant.UserConstants;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.core.domain.entity.SysRole;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.core.domain.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.ruoyi.common.core.domain.model.LoginBody;
 | 
	
		
			
				|  |  | +import com.ruoyi.common.core.domain.model.LoginUser;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.exception.CustomException;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.utils.SecurityUtils;
 | 
	
		
			
				|  |  |  import com.ruoyi.common.utils.StringUtils;
 | 
	
		
			
				|  |  |  import com.ruoyi.system.domain.SysPost;
 | 
	
		
			
				|  |  |  import com.ruoyi.system.domain.SysUserPost;
 | 
	
		
			
				|  |  |  import com.ruoyi.system.domain.SysUserRole;
 | 
	
		
			
				|  |  | -import com.ruoyi.system.mapper.SysPostMapper;
 | 
	
		
			
				|  |  | -import com.ruoyi.system.mapper.SysRoleMapper;
 | 
	
		
			
				|  |  | -import com.ruoyi.system.mapper.SysUserMapper;
 | 
	
		
			
				|  |  | -import com.ruoyi.system.mapper.SysUserPostMapper;
 | 
	
		
			
				|  |  | -import com.ruoyi.system.mapper.SysUserRoleMapper;
 | 
	
		
			
				|  |  | +import com.ruoyi.system.mapper.*;
 | 
	
		
			
				|  |  |  import com.ruoyi.system.service.ISysConfigService;
 | 
	
		
			
				|  |  |  import com.ruoyi.system.service.ISysUserService;
 | 
	
		
			
				|  |  | +import okhttp3.OkHttpClient;
 | 
	
		
			
				|  |  | +import okhttp3.Request;
 | 
	
		
			
				|  |  | +import okhttp3.Response;
 | 
	
		
			
				|  |  | +import org.slf4j.Logger;
 | 
	
		
			
				|  |  | +import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 用户 业务层处理
 | 
	
	
		
			
				|  | @@ -76,6 +72,19 @@ public class SysUserServiceImpl implements ISysUserService {
 | 
	
		
			
				|  |  |      @Value("${wechatProgram.sessionUrl}")
 | 
	
		
			
				|  |  |      private String sessionUrl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 仓储微信小程序应用id
 | 
	
		
			
				|  |  | +    @Value("${warehouseWechatProgram.appId}")
 | 
	
		
			
				|  |  | +    private String warehouseAppId;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 仓储微信小程序应用密钥
 | 
	
		
			
				|  |  | +    @Value("${warehouseWechatProgram.secret}")
 | 
	
		
			
				|  |  | +    private String warehouseSecret;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 仓储微信小程序获取用户session路径
 | 
	
		
			
				|  |  | +    @Value("${warehouseWechatProgram.sessionUrl}")
 | 
	
		
			
				|  |  | +    private String warehouseSessionUrl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 根据条件分页查询用户列表
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -437,32 +446,58 @@ public class SysUserServiceImpl implements ISysUserService {
 | 
	
		
			
				|  |  |       * @return 结果
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public SysUser weChatProgramLogin(LoginBody loginBody) {
 | 
	
		
			
				|  |  | +    public SysUser weChatProgramLogin(LoginBody loginBody,String usertype) {
 | 
	
		
			
				|  |  |          //声明客户端
 | 
	
		
			
				|  |  |          OkHttpClient client = new OkHttpClient();
 | 
	
		
			
				|  |  |          //构建Request
 | 
	
		
			
				|  |  | -        Request request = new Request.Builder().url(sessionUrl + "?appid=" + appId + "&secret=" + secret +
 | 
	
		
			
				|  |  | -                "&js_code=" + loginBody.getCode() + "&grant_type=authorization_code").build();
 | 
	
		
			
				|  |  | -        try {
 | 
	
		
			
				|  |  | -            Response response = client.newCall(request).execute();
 | 
	
		
			
				|  |  | -            //如果请求成功,解析数据
 | 
	
		
			
				|  |  | -            if (response.isSuccessful()) {
 | 
	
		
			
				|  |  | -                String body = response.body().string();
 | 
	
		
			
				|  |  | -                //得到一个JSON对象
 | 
	
		
			
				|  |  | -                JSONObject object = JSON.parseObject(body);
 | 
	
		
			
				|  |  | -                String openid = object.getString("openid");
 | 
	
		
			
				|  |  | -                String sessionKey = object.getString("session_key");
 | 
	
		
			
				|  |  | -                if (StringUtils.isNotEmpty(openid)) {
 | 
	
		
			
				|  |  | -                    log.info("通过code获取用户openId异常:" + object.toJSONString());
 | 
	
		
			
				|  |  | -                    SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | -                    sysUser.setOpenId(openid);
 | 
	
		
			
				|  |  | -                    sysUser.setSessionKey(sessionKey);
 | 
	
		
			
				|  |  | -                    return sysUser;
 | 
	
		
			
				|  |  | +        if(usertype.equals("00")){
 | 
	
		
			
				|  |  | +            Request request = new Request.Builder().url(warehouseSessionUrl + "?appid=" + warehouseAppId + "&secret=" + warehouseSecret +
 | 
	
		
			
				|  |  | +                    "&js_code=" + loginBody.getCode() + "&grant_type=authorization_code").build();
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                Response response = client.newCall(request).execute();
 | 
	
		
			
				|  |  | +                //如果请求成功,解析数据
 | 
	
		
			
				|  |  | +                if (response.isSuccessful()) {
 | 
	
		
			
				|  |  | +                    String body = response.body().string();
 | 
	
		
			
				|  |  | +                    //得到一个JSON对象
 | 
	
		
			
				|  |  | +                    JSONObject object = JSON.parseObject(body);
 | 
	
		
			
				|  |  | +                    String openid = object.getString("openid");
 | 
	
		
			
				|  |  | +                    String sessionKey = object.getString("session_key");
 | 
	
		
			
				|  |  | +                    if (StringUtils.isNotEmpty(openid)) {
 | 
	
		
			
				|  |  | +                        log.info("通过code获取用户openId异常:" + object.toJSONString());
 | 
	
		
			
				|  |  | +                        SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | +                        sysUser.setOpenId(openid);
 | 
	
		
			
				|  |  | +                        sysUser.setSessionKey(sessionKey);
 | 
	
		
			
				|  |  | +                        return sysUser;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            } catch (IOException e) {
 | 
	
		
			
				|  |  | +                e.printStackTrace();
 | 
	
		
			
				|  |  | +                log.info("用户获取openId异常:" + e);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            Request request = new Request.Builder().url(sessionUrl + "?appid=" + appId + "&secret=" + secret +
 | 
	
		
			
				|  |  | +                    "&js_code=" + loginBody.getCode() + "&grant_type=authorization_code").build();
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                Response response = client.newCall(request).execute();
 | 
	
		
			
				|  |  | +                //如果请求成功,解析数据
 | 
	
		
			
				|  |  | +                if (response.isSuccessful()) {
 | 
	
		
			
				|  |  | +                    String body = response.body().string();
 | 
	
		
			
				|  |  | +                    //得到一个JSON对象
 | 
	
		
			
				|  |  | +                    JSONObject object = JSON.parseObject(body);
 | 
	
		
			
				|  |  | +                    String openid = object.getString("openid");
 | 
	
		
			
				|  |  | +                    String sessionKey = object.getString("session_key");
 | 
	
		
			
				|  |  | +                    if (StringUtils.isNotEmpty(openid)) {
 | 
	
		
			
				|  |  | +                        log.info("通过code获取用户openId异常:" + object.toJSONString());
 | 
	
		
			
				|  |  | +                        SysUser sysUser = new SysUser();
 | 
	
		
			
				|  |  | +                        sysUser.setOpenId(openid);
 | 
	
		
			
				|  |  | +                        sysUser.setSessionKey(sessionKey);
 | 
	
		
			
				|  |  | +                        return sysUser;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +            } catch (IOException e) {
 | 
	
		
			
				|  |  | +                e.printStackTrace();
 | 
	
		
			
				|  |  | +                log.info("用户获取openId异常:" + e);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        } catch (IOException e) {
 | 
	
		
			
				|  |  | -            e.printStackTrace();
 | 
	
		
			
				|  |  | -            log.info("用户获取openId异常:" + e);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return null;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -547,7 +582,52 @@ public class SysUserServiceImpl implements ISysUserService {
 | 
	
		
			
				|  |  |       * @param loginBody 参数
 | 
	
		
			
				|  |  |       * @return  结果
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public SysUser selectUserByPhone(LoginBody loginBody) {
 | 
	
		
			
				|  |  | -        return userMapper.selectUserByTel(loginBody.getPhonenumber());
 | 
	
		
			
				|  |  | +    public SysUser selectUserByPhone(LoginBody loginBody ,String usertype) {
 | 
	
		
			
				|  |  | +        if(usertype.equals("00")){
 | 
	
		
			
				|  |  | +            return userMapper.warehouseSelectUserByTel(loginBody.getPhonenumber());
 | 
	
		
			
				|  |  | +        }else {
 | 
	
		
			
				|  |  | +            return userMapper.selectUserByTel(loginBody.getPhonenumber());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 获取用户手机号更新对应信息
 | 
	
		
			
				|  |  | +    @Transactional
 | 
	
		
			
				|  |  | +    public LoginUser warehouseCreateOrUpdateUser(SysUser user) {
 | 
	
		
			
				|  |  | +        LoginUser loginUser = new LoginUser();
 | 
	
		
			
				|  |  | +        // 判断是否提前存储过
 | 
	
		
			
				|  |  | +        SysUser sysUser = userMapper.selectUserByopenId(user.getOpenId());
 | 
	
		
			
				|  |  | +        boolean related = false;
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotNull(sysUser)) {
 | 
	
		
			
				|  |  | +            if ("1".equals(user.getStatus()) && "2".equals(user.getDelFlag())) {
 | 
	
		
			
				|  |  | +                // 提前关注公众号的信息
 | 
	
		
			
				|  |  | +                userMapper.deleteUserById(user.getUserId());
 | 
	
		
			
				|  |  | +                related = true;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 判断是否创建了驾驶员
 | 
	
		
			
				|  |  | +        SysUser pUser = userMapper.warehouseSelectUserByTel(user.getPhonenumber());
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotNull(pUser)) {
 | 
	
		
			
				|  |  | +            // 创建过
 | 
	
		
			
				|  |  | +            pUser.setOpenId(user.getOpenId());
 | 
	
		
			
				|  |  | +            if (related) {
 | 
	
		
			
				|  |  | +                pUser.setRelatedNo("T");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            pUser.setSessionKey(user.getSessionKey());
 | 
	
		
			
				|  |  | +            userMapper.updateUser(pUser);
 | 
	
		
			
				|  |  | +            loginUser.setUser(pUser);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            // 没有创建 则创建临时性用户数据
 | 
	
		
			
				|  |  | +            user.setNickName(" ");
 | 
	
		
			
				|  |  | +            user.setUserName(user.getPhonenumber());
 | 
	
		
			
				|  |  | +            user.setStatus("1");
 | 
	
		
			
				|  |  | +            user.setStatus("1");
 | 
	
		
			
				|  |  | +            user.setDelFlag("2");
 | 
	
		
			
				|  |  | +            user.setUserType("00");
 | 
	
		
			
				|  |  | +            user.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +            userMapper.insertUser(user);
 | 
	
		
			
				|  |  | +            loginUser.setUser(user);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return loginUser;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |