puzhibing
2023-08-22 00caef45a8833dc58919e23eb88a3484cfacdaa4
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserInfoController.java
@@ -1,6 +1,7 @@
package com.stylefeng.guns.modular.api;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.BigDecimalCodec;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.code.kaptcha.Constants;
import com.stylefeng.guns.core.common.constant.JwtConstants;
@@ -21,11 +22,17 @@
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
/**
@@ -54,6 +61,9 @@
    @Autowired
    private IBankCardService bankCardService;
    @Autowired
    private IOrderService orderService;
    @Value("${spring.mail.template-path}")
    private String templatePath;
@@ -134,7 +144,7 @@
                if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
                    return ResultUtil.error(language == 1 ? "图形验证码错误" : language == 2 ? "The graphic verification code is incorrect" : "Code de vérification graphique incorrect");
                }
                return userInfoService.queryCaptcha(phone, type);
                return userInfoService.queryCaptcha(phone, type, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
@@ -153,7 +163,7 @@
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String")
    })
    public ResultUtil queryCaptcha1(String phone, Integer type){
    public ResultUtil queryCaptcha1(String phone, Integer type, Integer language){
        if(ToolUtil.isNotEmpty(phone)){
            try {
                String substring = phone.substring(0, 1);
@@ -163,7 +173,7 @@
                if(phone.indexOf("233") < 0){
                    phone = "233" + phone;
                }
                return userInfoService.queryCaptcha(phone, type);
                return userInfoService.queryCaptcha(phone, type, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
@@ -207,24 +217,24 @@
                String path = templatePath +  "user/mainbox.html";
                Document document = Jsoup.parse(new File(path), "UTF-8");
                if(1 == language){
                    document.getElementById("english").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    document.getElementById("english").remove();
                    document.getElementById("french").remove();
                    Element user_chinese = document.getElementById("user_chinese");
                    user_chinese.text("您好 " + nickName + ",");
                    Element content_chinese = document.getElementById("content_chinese");
                    content_chinese.text(authCode);
                }
                if(2 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    document.getElementById("chinese").remove();
                    document.getElementById("french").remove();
                    Element user_chinese = document.getElementById("user_english");
                    user_chinese.text("Hello " + nickName + ",");
                    Element content_chinese = document.getElementById("content_english");
                    content_chinese.text(authCode);
                }
                if(3 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("english").attr("style", "display: none;");
                    document.getElementById("chinese").remove();
                    document.getElementById("english").remove();
                    Element user_french = document.getElementById("user_french");
                    user_french.text("Bonjour " + nickName + ",");
                    Element content_french = document.getElementById("content_french");
@@ -270,6 +280,20 @@
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            switch (phoneOperator){
                case "MTN":
                    phoneOperator = "GH-MTN-B2C";
                    break;
                case "TIGO":
                    phoneOperator = "GH-TIGO-B2C";
                    break;
                case "VODAFONE":
                    phoneOperator = "GH-VODAFONE-B2C";
                    break;
                case "AIRTEL":
                    phoneOperator = "GH-AIRTEL-B2C";
                    break;
            }
            return userInfoService.captchaLogin(phoneOperator, phone, code, registIp, lat, lng,null,null,null,language);
        }catch (Exception e){
            e.printStackTrace();
@@ -304,6 +328,20 @@
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            switch (phoneOperator){
                case "MTN":
                    phoneOperator = "GH-MTN-B2C";
                    break;
                case "TIGO":
                    phoneOperator = "GH-TIGO-B2C";
                    break;
                case "VODAFONE":
                    phoneOperator = "GH-VODAFONE-B2C";
                    break;
                case "AIRTEL":
                    phoneOperator = "GH-AIRTEL-B2C";
                    break;
            }
            return userInfoService.captchaLogin(phoneOperator, phone, code, uid, type, userType, language);
        }catch (Exception e){
@@ -494,6 +532,20 @@
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            switch (phoneOperator){
                case "MTN":
                    phoneOperator = "GH-MTN-B2C";
                    break;
                case "TIGO":
                    phoneOperator = "GH-TIGO-B2C";
                    break;
                case "VODAFONE":
                    phoneOperator = "GH-VODAFONE-B2C";
                    break;
                case "AIRTEL":
                    phoneOperator = "GH-AIRTEL-B2C";
                    break;
            }
            return userInfoService.bindingPhone(uid, phoneOperator, phone, code, language);
        }catch (Exception e){
            e.printStackTrace();
@@ -532,7 +584,7 @@
     */
    @ResponseBody
    @PostMapping("/api/user/queryUserInfo")
    @ApiOperation(value = "获取用户详情【1.0】", tags = {"用户端-个人中心"}, notes = "")
    @ApiOperation(value = "获取用户详情【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
@@ -706,6 +758,20 @@
            }
            if(phone.indexOf("233") < 0){
                phone = "233" + phone;
            }
            switch (phoneOperator){
                case "MTN":
                    phoneOperator = "GH-MTN-B2C";
                    break;
                case "TIGO":
                    phoneOperator = "GH-TIGO-B2C";
                    break;
                case "VODAFONE":
                    phoneOperator = "GH-VODAFONE-B2C";
                    break;
                case "AIRTEL":
                    phoneOperator = "GH-AIRTEL-B2C";
                    break;
            }
            return userInfoService.updatePhone(code, phoneOperator, phone, uid, language);
        }catch (Exception e){
@@ -989,6 +1055,39 @@
    }
    @ResponseBody
    @PostMapping("/base/user/queryOrderLicensePlate")
    @ApiOperation(value = "获取报失也车牌等信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城出行,4=同城小件物流,5=跨城小件物流)", name = "orderType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
    })
    public ResultUtil queryOrderLicensePlate(Integer orderType, Integer orderId){
        try {
            Map<String, Object> map = orderService.queryOrderLicensePlate(orderType, orderId);
            return ResultUtil.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @RequestMapping("/base/user/image")
    public String image(@RequestPart("file") MultipartFile file) {
        try {
            String pictureName = OBSUploadUtil.inputStreamUpload(file);
            return pictureName;
        } catch (IOException e1) {
            return null;
        }
    }
    @ResponseBody
    @PostMapping("/api/user/queryBankCardList")
    @ApiOperation(value = "获取银行卡列表【1.1】", tags = {"用户端-个人中心"}, notes = "")
@@ -1036,6 +1135,11 @@
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            BigDecimal bigDecimal = new BigDecimal(code);
            long max = Long.MAX_VALUE;
            if(bigDecimal.compareTo(new BigDecimal(max)) >= 0){
                return ResultUtil.error(language == 1 ? "银行卡号格式错误" : language == 2 ? "The format of bank card number is incorrect" : "Format incorrect du numéro de carte bancaire");
            }
            BankCard bankCard = bankCardService.selectOne(new EntityWrapper<BankCard>().eq("code", code));
            if(null != bankCard){
                return ResultUtil.error(language == 1 ? "银行卡重复" : language == 2 ? "Duplicate bank card" : "Double carte bancaire");
@@ -1059,7 +1163,7 @@
    @ResponseBody
    @PostMapping("/api/user/addBankCard")
    @PostMapping("/api/user/delBankCard")
    @ApiOperation(value = "删除银行卡【1.1】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "银行卡id", name = "id", required = true, dataType = "int"),
@@ -1074,4 +1178,51 @@
            return ResultUtil.runErr();
        }
    }
    /**
     * 下载pdf
     * @param orderId
     * @param orderType
     * @param response
     */
    @ResponseBody
    @GetMapping("/base/order/uploadReceiptPdf")
    public void uploadReceiptPdf(Integer orderId, Integer orderType, HttpServletResponse response){
        FileInputStream fileInputStream = null;
        ServletOutputStream outputStream = null;
        try {
            if(orderType == 1){
                fileInputStream = new FileInputStream(new File("/usr/local/nginx/html/files/pdf/ride_receipt_" + orderId + ".pdf"));
            }
            if(orderType == 4){
                fileInputStream = new FileInputStream(new File("/usr/local/nginx/html/files/pdf/parcel_receipt_" + orderId + ".pdf"));
            }
            BufferedInputStream bf = new BufferedInputStream(fileInputStream);
            outputStream = response.getOutputStream();
            response.setContentType(MediaType.APPLICATION_PDF_VALUE);
            response.setHeader("content-Disposition","attachment;filename=" + (orderId + "_" + orderType + ".pdf"));
            byte[] b = new byte[bf.available() + 1000];
            int i;
            while((i=bf.read(b))!=-1){
                outputStream.write(b,0, i);
            }
            outputStream.flush();
            outputStream.close();
            fileInputStream.close();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(null != outputStream){
                    outputStream.close();
                }
                if(null != fileInputStream){
                    fileInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}