From 19c35c58f8b767d7d9c57d0cf910fd091dc7669f Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 27 二月 2025 16:37:08 +0800
Subject: [PATCH] 2.0新增

---
 DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java |  158 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 2 deletions(-)

diff --git a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
index b5d83a3..d2cd7d2 100644
--- a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
+++ b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.internal.util.codec.Base64;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.core.common.constant.JwtConstants;
@@ -20,6 +21,7 @@
 import com.stylefeng.guns.modular.system.warpper.LoginWarpper;
 import com.stylefeng.guns.modular.system.warpper.RegisteredWarpper;
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
+import org.apache.http.entity.ContentType;
 import org.apache.shiro.authc.SimpleAuthenticationInfo;
 import org.apache.shiro.authc.UsernamePasswordToken;
 import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
@@ -27,11 +29,19 @@
 import org.apache.shiro.util.ByteSource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.*;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.*;
 import java.math.BigDecimal;
+import java.security.SecureRandom;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -125,6 +135,8 @@
 
     @Autowired
     private IOrderLogisticsService orderLogisticsService;
+    @Autowired
+    private ICompanyService companyService;
 
     @Value("${pushMinistryOfTransport}")
     private boolean pushMinistryOfTransport;
@@ -605,8 +617,9 @@
                     return ResultUtil.error("该车辆正在服务中,请更换其他车辆");
                 }
             }
-            List<TUseMoney> tUseMoney = useMoneyMapper.selectList(null);
-            if (tUseMoney.get(0).getMoney()>driver.getBalance()){
+//            List<TUseMoney> tUseMoney = useMoneyMapper.selectList(null);
+            Company company = companyService.selectById(driver.getCompanyId());
+            if (company.getDriverRestriction()>driver.getBalance()){
                 pushUtil.expireWork(uid,2);
                 return new ResultUtil(-1,"您的余额不足,请及时充值!");
             }
@@ -1546,8 +1559,149 @@
         redisUtil.remove("DEVICE_" + id);//清除车载端登录的标识
         return ResultUtil.success();
     }
+    @Autowired
+    private WeChatUtil weChatUtil;
+    @Autowired
+    private RestTemplate restTemplate;
+    @Override
+    public Driver generateCode(Driver userInfo) {
+        generateQrCode(userInfo);
+        return userInfo;
+    }
 
+    private void generateQrCode(Driver userInfo) {
+        if (userInfo.getCode()!=null){
+            return;
+        }
+        String accessToken = weChatUtil.getAccessToken();
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
+            Map<String, Object> param = new HashMap<>();
+//            param.put("page", "pageA/houseDetail");
+            param.put("check_path", false);
+            // 用户id 用于分享
+            param.put("scene", "uid="+userInfo.getId()+"userType=2");
+            param.put("env_version", "trial");
+            param.put("width", 200); //二维码尺寸
+            param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
+            param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
+            Map<String, Object> line_color = new HashMap<>();
+            line_color.put("r", 0);
+            line_color.put("g", 0);
+            line_color.put("b", 0);
+            param.put("line_color", line_color);
+            System.err.println("调用生成微信URL接口传参:" + param);
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity requestEntity = new HttpEntity(param, headers);
+//            HashMap<String, String> map = new HashMap<>();
+//            map.put("path", path);
+//            HttpHeaders headers = new HttpHeaders();
+//            headers.setContentType(MediaType.APPLICATION_JSON);
+//            HttpEntity requestEntity = new HttpEntity(map, headers);
+//            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+//            byte[] bytes = rep.getBody();
+            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+            System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
+            byte[] result = entity.getBody();
+            System.err.println(Base64.encodeBase64String(result));
 
+            inputStream = new ByteArrayInputStream(result);
+            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result);
+            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
+            String pictureName = OssUploadUtil.ossUploadCode(file,finalFileName);
+            System.err.println(pictureName);
+            userInfo.setCode(pictureName);
+            this.updateById(userInfo);
+
+        } catch (Exception e) {
+            System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+    @Override
+    public String generateQrCodeTemp() {
+
+        String accessToken = weChatUtil.getAccessToken();
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
+            Map<String, Object> param = new HashMap<>();
+//            param.put("page", "pageA/houseDetail");
+            param.put("check_path", false);
+            // 用户id 用于分享
+            param.put("scene", "uid="+1+"userType=1");
+//            param.put("env_version", "trial");
+//            param.put("width", 200); //二维码尺寸
+//            param.put("is_hyaline", true); // 是否需要透明底色, is_hyaline 为true时,生成透明底色的小程序码 参数仅对小程序码生效
+//            param.put("auto_color", true); // 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调 参数仅对小程序码生效
+//            Map<String, Object> line_color = new HashMap<>();
+//            line_color.put("r", 0);
+//            line_color.put("g", 0);
+//            line_color.put("b", 0);
+//            param.put("line_color", line_color);
+            System.err.println("调用生成微信URL接口传参:" + param);
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity requestEntity = new HttpEntity(param, headers);
+//            HashMap<String, String> map = new HashMap<>();
+//            map.put("path", path);
+//            HttpHeaders headers = new HttpHeaders();
+//            headers.setContentType(MediaType.APPLICATION_JSON);
+//            HttpEntity requestEntity = new HttpEntity(map, headers);
+//            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+//            byte[] bytes = rep.getBody();
+            ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+            System.err.println("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody());
+            byte[] result = entity.getBody();
+            System.err.println(Base64.encodeBase64String(result));
+
+            inputStream = new ByteArrayInputStream(result);
+            String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg";
+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result);
+            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
+            String pictureName = OssUploadUtil.ossUploadCode(file,finalFileName);
+            System.err.println(pictureName);
+            return Base64.encodeBase64String(result);
+
+        } catch (Exception e) {
+            System.err.println("调用小程序生成微信永久小程序码URL接口异常" + e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return "";
+    }
     /**
      * 获取编号
      * @return

--
Gitblit v1.7.1