Pu Zhibing
7 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/UserInfoController.java
@@ -6,6 +6,7 @@
import com.google.code.kaptcha.Constants;
import com.stylefeng.guns.core.common.constant.JwtConstants;
import com.stylefeng.guns.core.common.exception.InvalidKaptchaException;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.BankCard;
@@ -13,8 +14,11 @@
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils;
import com.stylefeng.guns.modular.system.warpper.*;
import com.stylefeng.guns.modular.taxi.model.TransactionDetails;
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -23,6 +27,8 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -48,6 +54,8 @@
@RestController
@RequestMapping("")
public class UserInfoController {
    Logger log = LoggerFactory.getLogger(UserInfoController.class);
    @Autowired
    private IUserInfoService userInfoService;
@@ -77,6 +85,13 @@
    private TEmailService emailService;
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
    @Autowired
    private IPaymentRecordService paymentRecordService;
    @Autowired
    private FleetEngineUtil fleetEngineUtil;
    private String salt = "&a.s";
@@ -189,7 +204,32 @@
            return ResultUtil.paranErr();
        }
    }
    /**
     * 短信回调通知
     * @param request
     */
    @ResponseBody
    @PostMapping("/base/sendCellulantMessageCallback")
    public void sendCellulantMessageCallback(HttpServletRequest request){
        try {
            StringBuilder sb = new StringBuilder();
            InputStream inputStream = request.getInputStream();
            String s;
            BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            while ((s = in.readLine()) != null) {
                sb.append(s);
            }
            in.close();
            inputStream.close();
            log.info("短信通知回调:" + sb.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    @ResponseBody
    @PostMapping("/base/sedEmail")
    @ApiOperation(value = "获取邮箱验证码【1.0】", tags = {"用户端-登录"}, notes = "")
@@ -260,12 +300,12 @@
                EmailUtil.send(email, language == 1 ? "邮箱验证" : language == 2 ? "Verification code" : "Code de validation",  document.html());
                //开始生成pdf收据和html收据
                File file = new File("/usr/local/nginx/html/files/html/");
                File file = new File("/home/igotechgh/nginx/html/files/html/");
                if(!file.exists()){
                    file.mkdirs();
                }
                String randomString = ToolUtil.getRandomString(10);
                file = new File("/usr/local/nginx/html/files/html/mainbox_" + randomString + ".html");
                file = new File("/home/igotechgh/nginx/html/files/html/mainbox_" + randomString + ".html");
                if(!file.exists()){
                    file.createNewFile();
                }
@@ -274,7 +314,7 @@
                fileWriter.flush();
                fileWriter.close();
                String link ="http://182.160.16.251:81/files/html/mainbox_" + randomString + ".html";
                String link ="https://igo.i-go.group/files/html/mainbox_" + randomString + ".html";
                TEmail tEmail = new TEmail();
                tEmail.setLink(link);
                tEmail.setUserId(uid);
@@ -709,8 +749,9 @@
            Map<String, Object> map = userInfoService.queryUser(language, phone);
            if(null != map){
                return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
            }else{
                return ResultUtil.error(language == 1 ? "此账号不存在" : language == 2 ? "The account does not exist" : "Ce compte n’existe pas");
            }
            return ResultUtil.success(new JSONObject());
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -757,11 +798,15 @@
            @ApiImplicitParam(value = "电话号码,没有传空字符串", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil setUrgentUser(String name, String phone, HttpServletRequest request){
    public ResultUtil setUrgentUser(String name, String phone, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            if(ToolUtil.isEmpty(userInfo.getPhone())){
                return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable.");
            }
            String substring = phone.substring(0, 1);
            if("0".equals(substring)){
@@ -1143,12 +1188,12 @@
    @ResponseBody
    @RequestMapping("/base/user/image")
    public String image(@RequestPart("file") MultipartFile file) {
    public ResultUtil image(@RequestPart("file") MultipartFile file) {
        try {
            String pictureName = OBSUploadUtil.inputStreamUpload(file);
            return pictureName;
        } catch (IOException e1) {
            return null;
            String pictureName = GoogleCloudStorageUtil.upload(file);
            return ResultUtil.success(pictureName);
        } catch (Exception e1) {
            return ResultUtil.runErr();
        }
    }
@@ -1196,6 +1241,10 @@
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            if(ToolUtil.isEmpty(userInfo.getPhone())){
                return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable.");
            }
            BigDecimal bigDecimal = new BigDecimal(code);
            long max = Long.MAX_VALUE;
@@ -1248,15 +1297,33 @@
    @PostMapping("/api/user/queryRechargeRecord")
    @ApiOperation(value = "用户查询充值记录", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
            @ApiImplicitParam(value = "语言", name = "language", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil queryRechargeRecord(HttpServletRequest request){
    public ResultUtil queryRechargeRecord(Integer pageNum, Integer size,Integer language,HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(transactionDetailsService.queryRechargeRecord(uid));
            RechargeRecordWarpper rechargeRecordWarpper = new RechargeRecordWarpper();
            List<Map<String,Object>> paymentRecord = paymentRecordService.queryRechargeRecord(uid, pageNum, size);
            for (Map<String, Object> map : paymentRecord) {
                if(null != map.get("insertTime")){
                    String time = map.get("insertTime").toString();
                    map.put("insertTime", DateUtil.conversionFormat(language, time));
                }
            }
            // 分装返回充值记录实体
            List<TransactionDetailsWarpper> transactionDetailsWarpper = TransactionDetailsWarpper.getTransactionDetailsWarpper(paymentRecord);
            // 查询充值金额总和
            double sum = paymentRecordService.queryRechargeMoneySum(uid);
            rechargeRecordWarpper.setSum(sum);
            rechargeRecordWarpper.setTransactionDetailsWarpper(transactionDetailsWarpper);
            return ResultUtil.success(rechargeRecordWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -1276,10 +1343,10 @@
        ServletOutputStream outputStream = null;
        try {
            if(orderType == 1){
                fileInputStream = new FileInputStream(new File("/usr/local/nginx/html/files/pdf/ride_receipt_" + orderId + ".pdf"));
                fileInputStream = new FileInputStream(new File("/home/igotechgh/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"));
                fileInputStream = new FileInputStream(new File("/home/igotechgh/nginx/html/files/pdf/parcel_receipt_" + orderId + ".pdf"));
            }
            BufferedInputStream bf = new BufferedInputStream(fileInputStream);
            outputStream = response.getOutputStream();
@@ -1308,4 +1375,78 @@
            }
        }
    }
    @ResponseBody
    @PostMapping("/api/user/getFleetEngineAuth")
    @ApiOperation(value = "获取google地图授权token", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "行程id", name = "tripId", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<Map<String, Object>> getFleetEngineAuth(String tripId, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            Map<String, Object> s = fleetEngineUtil.fleetEngineAuth(1, tripId);
            return ResultUtil.success(s);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/base/user/textToSpeech")
    public String textToSpeech(String languageCode, String text, String fileName){
        try {
            String s = TextToSpeechUtil.create(languageCode, text, fileName + ".mp3");
            //定时任务删除语音文件
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    try {
                        // 使用Runtime执行命令
                        Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName + ".mp3");
                        // 读取命令的输出
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            System.out.println(line);
                        }
                        // 等待命令执行完成
                        process.waitFor();
                        // 关闭流
                        reader.close();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 30000);
            return s;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/base/user/delUserInfo")
    public ResultUtil delUserInfo(String username, String password){
        UserInfo userInfo = userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("phone", username)
                .ne("flag", 3));
        if(null == userInfo){
            return ResultUtil.error("Invalid account");
        }
        if(!ShiroKit.md5(password, salt).equals(userInfo.getPassWord())){
            return ResultUtil.error("Wrong password");
        }
        userInfo.setFlag(3);
        userInfoService.updateById(userInfo);
        return ResultUtil.success();
    }
}