package com.stylefeng.guns.modular.api; import cn.hutool.core.io.FileUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.config.properties.GunsProperties; import com.stylefeng.guns.core.util.DateUtil; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService; import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics; import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.dao.RegionMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.model.vo.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.util.WeChatUtil; import com.stylefeng.guns.modular.system.util.qianyuntong.NCOSSUtil; import com.stylefeng.guns.modular.system.util.qianyuntong.QianYunTongConfig; import com.stylefeng.guns.modular.system.warpper.*; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.http.*; import org.springframework.util.Base64Utils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.security.SecureRandom; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** * 司机控制器 */ @Api @CrossOrigin @RestController @RequestMapping("") @Slf4j public class DriverController { @Resource private RedisTemplate redisTemplate; @Autowired private IDriverService driverService; @Autowired private IOrderPositionService orderPositionService; @Autowired private ISmsrecordService smsrecordService; @Autowired private IDriverOrdersService driverOrdersService; @Autowired private ICarService carService; @Autowired private RegionMapper regionMapper; @Autowired private IOrderTaxiService orderTaxiService; @Autowired private IIncomeService incomeService; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Autowired private IOrderCrossCityService orderCrossCityService; @Autowired private IOrderLogisticsService orderLogisticsService; @Autowired private GunsProperties gunsProperties; @Autowired private ICompanyService companyService; @Autowired private ICompanyCityService companyCityService; @Autowired private TDriverPromotionActivityService driverPromotionActivityService; @Autowired private QianYunTongConfig qianYunTongConfig; /** * 获取短信验证码 * * @param phone * @return */ @ResponseBody @PostMapping("/base/driver/queryCaptcha") @ApiOperation(value = "获取短信验证码", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String") }) public ResultUtil queryCaptcha(String phone, Integer type) { if (ToolUtil.isNotEmpty(phone)) { try { return driverService.queryCaptcha(phone, type); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } else { return ResultUtil.paranErr(); } } /** * 验证短信验证码 * * @param phone * @param code * @return */ @ResponseBody @PostMapping("/base/driver/checkCaptcha") @ApiOperation(value = "验证短信验证码", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String") }) public ResultUtil checkCaptcha(String phone, String code){ try { boolean b = driverService.checkCaptcha(phone, code); if(b){ Driver driver = driverService.queryByPhone(phone); smsrecordService.saveData(null == driver ? 5 : 8, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); } return b ? ResultUtil.success() : ResultUtil.error("验证码无效"); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 司机提交注册申请 * @return */ @ResponseBody @PostMapping("/base/driver/registeredDriver") @ApiOperation(value = "司机提交注册申请", tags = {"分享专用"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"), @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "String"), @ApiImplicitParam(value = "分享的用户id", name = "uid", required = true, dataType = "int"), @ApiImplicitParam(value = "用户类型(1=用户,2=司机)", name = "type", required = true, dataType = "int"), @ApiImplicitParam(value = "注册类型(1=司机注册,2=用户注册)", name = "userType", required = true, dataType = "int") }) public ResultUtil registeredDriver(String phone, String code, String password, Integer uid, Integer type, Integer userType){ try { return driverService.registeredDriver(phone, code, password, uid, type, userType); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 司机注册 * @param phone * @param code * @param password * @return */ @ResponseBody @PostMapping("/base/driver/registeredDriver_") @ApiOperation(value = "司机提交注册申请", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"), @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "String") }) public ResultUtil registeredDriver_(String phone, String code, String password){ try { return driverService.registeredDriver(phone, code, password); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/base/driver/queryNeedCertificate") @ApiOperation(value = "注册完善个人信息根据选择的从业地判断是否需要网约车资格证", tags = {"司机端-注册"}, notes = "0=城市未开通,1=是,2=否") @ApiImplicitParams({ @ApiImplicitParam(value = "城市行政编号", name = "code", required = true, dataType = "String") }) public ResultUtil queryNeedCertificate(String code){ try { Integer integer = driverService.queryNeedCertificate(code); return ResultUtil.success(integer == null ? 0 : integer); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 司机注册后完善个人信息 * @param registeredWarpper * @return */ @ResponseBody @PostMapping("/base/driver/updateDriver") @ApiOperation(value = "司机注册后完善个人信息", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "司机id", name = "uid", required = true, dataType = "int") }) public ResultUtil updateDriver(RegisteredWarpper registeredWarpper, Integer uid){ try { return driverService.updateDriver(registeredWarpper, uid); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 司机注册审核后的短信 * * @param uid * @param type * @return */ @ResponseBody @PostMapping("/base/driver/sendsms") public ResultUtil sendsms(Integer uid, Integer type) { try { Driver driver = driverService.selectById(uid); String templateCode = null; switch (type) { case 1: templateCode = "SMS_229648175";//身份验证 break; case 2: templateCode = "SMS_229613335";//登录确认 break; case 3: templateCode = "SMS_229613333";//用户注册 break; case 4: templateCode = "SMS_229613329";//修改密码 break; case 5: templateCode = "SMS_229648168";//司机注册成功 break; case 6: templateCode = "SMS_229613326";//司机注册失败 break; } // String s = aLiSendSms.sendSms(driver.getPhone(), templateCode, "{}"); // SMSUtil.sendVerifyCode(driver.getPhone()); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 忘记密码操作 * @param phone * @param code * @param password * @return */ @ResponseBody @PostMapping("/base/driver/resetPassword") @ApiOperation(value = "忘记密码操作", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"), @ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "String") }) public ResultUtil resetPassword(String phone, String code, String password){ try { return driverService.resetPassword(phone, code, password); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取忘记密码页面的电话 * @return */ @ResponseBody @PostMapping("/base/driver/queryPhone") @ApiOperation(value = "获取忘记密码页面的电话", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "当前定位城市行政编号(510100)", name = "code", required = true, dataType = "String") }) public ResultUtil queryPhone(String code){ try { Map map = driverService.queryPhone(code); return ResultUtil.success(map); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 司机登录操作 * @param phone * @param password * @return */ @ResponseBody @PostMapping("/base/driver/driverLogin") @ApiOperation(value = "登录操作", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "String") }) public ResultUtil driverLogin(String phone, String password){ try { return driverService.driverLogin(phone, password); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取首页统计数据 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryHomeData") @ApiOperation(value = "获取首页统计数据", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryHomeData(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Map map = driverService.queryHomeData(uid); return ResultUtil.success(HomeWarpper.getHomeWarpper(map)); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/queryHomeDataFromDriver") @ApiOperation(value = "获取首页统计数据(黔云通)", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryHomeDataFromDriver(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } DriverIndexVo vo = driverService.queryHomeDataFromDriver(uid); return ResultUtil.success(vo); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/queryOrderDataFromDriver") @ApiOperation(value = "获取订单统计数据(黔云通)", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(value = "2022-02-02 - 2033-03-03", name = "time", required = false, dataType = "String"), @ApiImplicitParam(value = "pageNumber", name = "pageNumber", required = true, dataType = "int"), @ApiImplicitParam(value = "pageSize", name = "pageSize", required = true, dataType = "int") }) public ResultUtil queryOrderDataFromDriver(String time,Integer pageNumber,Integer pageSize,HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Page driverOrderDataVoPage = new Page<>(pageNumber, pageSize); DriverOrderDataVo vo = driverService.queryOrderDataFromDriver(time,driverOrderDataVoPage,uid); return ResultUtil.success(vo); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/queryOrderMoneyFromDriver") @ApiOperation(value = "获取订单收入统计数据(黔云通)", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(value = "2022-02-02 - 2033-03-03", name = "time", required = false, dataType = "String"), @ApiImplicitParam(value = "pageNumber", name = "pageNumber", required = true, dataType = "int"), @ApiImplicitParam(value = "pageSize", name = "pageSize", required = true, dataType = "int") }) public ResultUtil queryOrderMoneyFromDriver(String time, Integer pageNumber, Integer pageSize, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Page driverOrderDataVoPage = new Page<>(pageNumber, pageSize); DriverOrderMoneyDataVo vo = driverService.queryOrderMoneyFromDriver(time,driverOrderDataVoPage,uid); return ResultUtil.success(vo); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/queryOrderPromotionFromDriver") @ApiOperation(value = "获取订单推广统计数据(黔云通)", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(value = "2022-02-02 - 2033-03-03", name = "time", required = false, dataType = "String"), @ApiImplicitParam(value = "pageNumber", name = "pageNumber", required = true, dataType = "int"), @ApiImplicitParam(value = "pageSize", name = "pageSize", required = true, dataType = "int") }) public ResultUtil queryOrderPromotionFromDriver(String time, Integer pageNumber, Integer pageSize, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Page driverOrderDataVoPage = new Page<>(pageNumber, pageSize); DriverOrderPromotionDataVo vo = driverService.queryOrderPromotionFromDriver(time,driverOrderDataVoPage,uid); return ResultUtil.success(vo); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/getPromotionInfo") @ApiOperation(value = "获取推广说明(黔云通)", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) public ResultUtil getPromotionInfo(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Driver driver = driverService.selectById(uid); String areaCode = driver.getAreaCode(); TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper() .eq("districtCode", areaCode) .eq("status", 2) .last("LIMIT 1")); if(tDriverPromotionActivity!=null){ return ResultUtil.success(tDriverPromotionActivity.getActivityDesc()); } return ResultUtil.success(""); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ApiOperation(value = "个人的小程序码(分享码)/链接", tags = {"司机端-首页"}, notes = "") @GetMapping("/api/driver/personCode") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) public ResultUtil> personCode(HttpServletRequest request) { try { Integer uid = driverService.getUserIdFormRedis(request); if (null == uid) { return ResultUtil.tokenErr(); } Driver driver = driverService.selectById(uid); String accessToken=null; Object img = redisTemplate.opsForValue().get("DRIVER_WX_IMG" + uid); // 获取调用凭证accessToken if(ToolUtil.isEmpty(driver.getShareLink())|| ToolUtil.isEmpty(img)){ accessToken = getAccessToken(); } int index=0; if(ToolUtil.isEmpty(img)) { RestTemplate rest = new RestTemplate(); String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; Map param = new HashMap<>(); param.put("path", "pages/home/home?driverId=" + uid); param.put("width", 430); //二维码尺寸 HttpRequest post = HttpUtil.createPost(url); post.body(JSON.toJSONString(param)); byte[] result = post.execute().bodyBytes(); // base64 img = Base64.getEncoder().encodeToString(result); redisTemplate.opsForValue().set("DRIVER_WX_IMG" + uid, img,30, TimeUnit.DAYS); } String urlLink = driver.getShareLink(); if(ToolUtil.isEmpty(urlLink)) { index=1; String url1 = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + accessToken; Map param1 = new HashMap<>(); param1.put("path", "pages/home/home"); param1.put("query", "driverId=" + uid); HttpRequest post = HttpUtil.createPost(url1); // map转json String jsonString = JSON.toJSONString(param1); post.body(jsonString); HttpResponse execute = post.execute(); String body = execute.body(); urlLink = JSONObject.parseObject(body).get("url_link").toString(); driver.setShareLink(urlLink); } if(index==1){ driverService.updateById(driver); } HashMap stringStringHashMap = new HashMap<>(); stringStringHashMap.put("url_link",urlLink); stringStringHashMap.put("img",img); return ResultUtil.success(stringStringHashMap); } catch (Exception e) { log.error("调用小程序生成微信永久小程序码URL接口异常", e); } return ResultUtil.error("获取二维码失败"); } @Value("${wx.url}") private String ACCESS_TOKEN_URL; @Value("${wx.appletsAppSecret}") private String memberAppSecret; @Value("${wx.appletsAppid}") private String wxAppId; @Autowired private RestTemplate restTemplate; public String getAccessToken() { String requestUrl = MessageFormat.format(ACCESS_TOKEN_URL,wxAppId,memberAppSecret); String respBody = restTemplate.getForEntity(requestUrl, String.class).getBody(); JSONObject jsonObject = JSONObject.parseObject(respBody); return jsonObject.getString("access_token"); } /** * 司机上下班操作 * @param type * @param request * @return */ @ResponseBody @PostMapping("/api/driver/work") @ApiOperation(value = "司机上下班操作", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "上班的业务类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城)多个已逗号分隔", name = "type", required = false, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil work(String type, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return driverService.work(uid, type); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/work2") @ApiOperation(value = "司机上下班操作,同时设置接单类型", tags = {"司机端-车载端"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "上班的业务类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城)多个已逗号分隔", name = "type", required = false, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil work2(String type, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return driverService.work2(uid, type); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @PostMapping("/api/driver/queryHomeNum") @ApiOperation(value = "获取首页统计数据", tags = {"司机端-车载端"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryHomeNum(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Map map = driverService.queryHomeNum(uid); return ResultUtil.success(map); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 上班时选择的业务类型 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryMyBusiness") @ApiOperation(value = "上班时选择的业务类型", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryMyBusiness(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } // TODO: 2020/7/21 修改为个人中心中设置的接单业务类型。 List list = driverService.queryMyBusiness(uid); List integers = driverOrdersService.queryOrders(uid); List data = new ArrayList<>(); for(BaseWarpper baseWarpper : list){ if(integers.contains(baseWarpper.getId())){ data.add(baseWarpper); } } return ResultUtil.success(data); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 存储订单服务中的司机位置 * @param orderPosition * @return */ @ResponseBody @PostMapping("/base/savePosition") public String savePosition(OrderPosition orderPosition){ try { orderPositionService.saveData(orderPosition); return JSON.toJSONString(ResultUtil.success()); }catch (Exception e){ e.printStackTrace(); return JSON.toJSONString(ResultUtil.runErr()); } } @ResponseBody @PostMapping("/base/driver/queryInfo_") @ApiOperation(value = "根据用户id获取数据", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "司机id", name = "uid", required = true, dataType = "int"), }) public ResultUtil queryInfo_(Integer uid){ try { Map map = driverService.queryInfo(uid); return ResultUtil.success(DriverInfoWarpper.getDriverInfoWarpper(map)); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取个人中心详情 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryInfo") @ApiOperation(value = "获取个人中心详情", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryInfo(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Map map = driverService.queryInfo(uid); return ResultUtil.success(DriverInfoWarpper.getDriverInfoWarpper(map)); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 修改手机号码 * @param phone * @param code * @param request * @return */ @ResponseBody @PostMapping("/api/driver/updatePhone") @ApiOperation(value = "修改手机号码", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "新电话号码", name = "phone", required = true, dataType = "String"), @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil updatePhone(String phone, String code, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return driverService.updatePhone(phone, code, uid); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 修改密码 * @param password * @param request * @return */ @ResponseBody @PostMapping("/api/driver/updatePassword") @ApiOperation(value = "修改密码", tags = {"司机端-个人中心"}, notes = "修改前需要验证短信验证码") @ApiImplicitParams({ @ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil updatePassword(String password, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } driverService.updatePassword(password, uid); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取设置接单的业务类型列表 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/querySetOrders") @ApiOperation(value = "获取设置接单的业务类型列表", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> querySetOrders(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List list = driverService.queryMyBusiness(uid); List integers = driverOrdersService.queryOrders(uid); List data = new ArrayList<>(); for(BaseWarpper b : list){ OrdersWarpper ordersWarpper = new OrdersWarpper(); ordersWarpper.setType(b.getId()); ordersWarpper.setName(b.getName()); ordersWarpper.setState(integers.contains(b.getId()) ? 2 : 1); data.add(ordersWarpper); } return ResultUtil.success(data); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 设置接单规则 * @param type * @param request * @return */ @ResponseBody @PostMapping("/api/driver/updateOrders") @ApiOperation(value = "设置接单规则", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城)", name = "type", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil updateOrders(Integer type, HttpServletRequest request){ try{ Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return driverOrdersService.updateOrders(uid, type); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取当前车辆及空闲车辆 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryMyCar") @ApiOperation(value = "获取当前车辆及空闲车辆 新增useState 1使用中 2空闲", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryMyCar(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Map map = carService.queryCars(uid); return ResultUtil.success(map); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 更换车辆 * @param carId * @param request * @return */ @ResponseBody @PostMapping("/api/driver/replaceCar") @ApiOperation(value = "更换车辆", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "车辆id", name = "carId", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil replaceCar(Integer carId, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return driverService.replaceCar(carId, uid); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取客服电话 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryPhone") @ApiOperation(value = "获取客服电话(黔云通)", tags = {"司机端-个人中心"}, notes = "车队=franchisee,分公司=branch,平台=platform") @ApiImplicitParams({ @ApiImplicitParam(value = "当前行政区划代码", name = "code", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryPhone(String code, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } Map map = driverService.queryPhone(uid, code); return ResultUtil.success(map); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @Autowired private IReassignService reassignService; @Autowired private ITimeOutAppealService timeOutAppealService; @Autowired private ITComplaintDeductmoneyService complaintDeductmoneyService; /** * 获取扣款明细 * @param pageNum * @param size * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryPenalties") @ApiOperation(value = "获取扣款明细", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryPenalties(Integer pageNum, Integer size, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } // List> list = driverService.queryPenalties(pageNum, size, uid); ArrayList integers = new ArrayList<>(); integers.add(1); integers.add(6); List list1 = reassignService.selectList(new EntityWrapper().eq("originalDriverId",uid).ne("state",6).ne("state",1)); List data = new ArrayList<>(); /// 存入改派处罚扣款 for (Reassign reassign : list1) { BaseWarpper baseWarpper = new BaseWarpper(); String insertTime = DateUtil.format(reassign.getInsertTime(),"yyyy-MM-dd HH:mm"); baseWarpper.setAmount(reassign.getMoney()); baseWarpper.setName("改派处罚"); baseWarpper.setDay(insertTime); data.add(baseWarpper); } // List list2 = timeOutAppealService.selectList(new EntityWrapper().eq("driverId",uid)); List list2 = orderLogisticsService.selectList(new EntityWrapper().eq("driverId",uid).gt("timeOutMoney",0)); for (OrderLogistics timeOutAppeal : list2) { BaseWarpper baseWarpper = new BaseWarpper(); String insertTime = DateUtil.format(timeOutAppeal.getEndServiceTime(),"yyyy-MM-dd HH:mm"); baseWarpper.setDay(insertTime); baseWarpper.setName("小件物流超时扣款"); baseWarpper.setAmount(timeOutAppeal.getTimeOutMoney()); data.add(baseWarpper); } List list3 = complaintDeductmoneyService.selectList(new EntityWrapper().eq("driverId",uid)); for (TComplaintDeductmoney tComplaintDeductmoney : list3) { BaseWarpper baseWarpper = new BaseWarpper(); String insertTime = DateUtil.format(tComplaintDeductmoney.getCreateTime(),"yyyy-MM-dd HH:mm"); baseWarpper.setDay(insertTime); baseWarpper.setName("投诉扣款"); baseWarpper.setAmount(tComplaintDeductmoney.getMoney()); data.add(baseWarpper); } List collect = data.stream().sorted(Comparator.comparing(BaseWarpper::getDay).reversed()).collect(Collectors.toList()); List data1 = new ArrayList<>(); // 手动分页 for (int i=(pageNum-1)*size; i> queryActivityIncome(Integer pageNum, Integer size, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } // List> list = driverService.queryActivityIncome(uid, pageNum, size); // List data = new ArrayList<>(); // for(Map map : list){ // BaseWarpper baseWarpper = new BaseWarpper(); // baseWarpper.setDay(String.valueOf(null != map.get("time") ? map.get("time") : "")); // baseWarpper.setAmount(Double.valueOf(String.valueOf(null != map.get("money") ? map.get("money") : 0))); // baseWarpper.setName("活动奖励"); // data.add(baseWarpper); // } List list1 = incomeService.selectList(new EntityWrapper().eq("userType",2).eq("objectId",uid)); List data = new ArrayList<>(); /// 存入改派处罚扣款 for (Income income : list1) { BaseWarpper baseWarpper = new BaseWarpper(); String insertTime = DateUtil.format(income.getInsertTime(),"yyyy-MM-dd HH:mm"); baseWarpper.setDay(insertTime); baseWarpper.setAmount(income.getMoney()); // TODO 司机收益明细订单类型 System.out.println(income.getId()); System.err.println(income.getOrderType()); // baseWarpper.setOrderType(income.getOrderType()); if (income.getType() == 1){ if(Objects.nonNull(income.getActivityType())){ switch (income.getActivityType()){ case 1: baseWarpper.setName("邀请司机注册"); break; case 2: baseWarpper.setName("邀请用户注册"); break; case 3: baseWarpper.setName("快车累计在线"); break; case 4: baseWarpper.setName("车租车累计在线"); break; case 5: baseWarpper.setName("跨城累计在线"); break; case 6: baseWarpper.setName("订单数奖励"); break; } }else { baseWarpper.setName("活动奖励"); } System.out.println(baseWarpper); data.add(baseWarpper); } // else if (income.getType() == 2){ // baseWarpper.setName("跑单收入"); // }else if (income.getType() == 6){ // baseWarpper.setName("感谢费"); // } // data.add(baseWarpper); } List list2 = timeOutAppealService.selectList(new EntityWrapper().eq("driverId",uid)); for (TimeOutAppeal timeOutAppeal : list2) { BaseWarpper baseWarpper = new BaseWarpper(); String insertTime = DateUtil.format(timeOutAppeal.getCreateTime(),"yyyy-MM-dd HH:mm"); baseWarpper.setDay(insertTime); baseWarpper.setName("小件物流超时退款"); if (timeOutAppeal.getState() == 2){ baseWarpper.setAmount(timeOutAppeal.getReturnMoney()); data.add(baseWarpper); } } List collect = data.stream().sorted(Comparator.comparing(BaseWarpper::getDay).reversed()).collect(Collectors.toList()); List data1 = new ArrayList<>(); // 手动分页 for (int i=(pageNum-1)*size; i> queryTotalRevenue(Integer pageNum, Integer size, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List> list = driverService.queryTotalRevenue(uid, pageNum, size); List data = new ArrayList<>(); for(Map map : list){ BaseWarpper baseWarpper = new BaseWarpper(); baseWarpper.setDay(String.valueOf(null != map.get("time") ? map.get("time") : "")); baseWarpper.setAmount(Double.valueOf(String.valueOf(null != map.get("money") ? map.get("money") : 0))); switch (Integer.valueOf(String.valueOf(null != map.get("orderType") ? map.get("orderType") : 0))){ case 1: baseWarpper.setName("快车"); break; case 2: baseWarpper.setName("出租车"); break; case 3: baseWarpper.setName("城际出行"); break; case 4: baseWarpper.setName("同城小件物流"); break; case 5: baseWarpper.setName("跨城小件物流"); break; } Map map1 = new HashMap<>(); switch (Integer.valueOf(map.get("orderType").toString())){ case 1: OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(map.get("incomeId").toString()); if(null != orderPrivateCar){ List incomes = incomeService.queryData(1, null, 2, orderPrivateCar.getId(), 1); map1.put("travelMoney", null != orderPrivateCar.getOrderMoney() ? orderPrivateCar.getOrderMoney() : 0);//行程费 map1.put("parkMoney", null != orderPrivateCar.getParkMoney() ? orderPrivateCar.getParkMoney() : 0);//停车费 map1.put("tipMoney", 0);//小费 map1.put("roadTollMoney", null != orderPrivateCar.getRoadTollMoney() ? orderPrivateCar.getRoadTollMoney() : 0);//过路费 Double rakeMoney=0.0; if(incomes.size()>0){ if(incomes.get(0).getMoney()<0){ rakeMoney = Math.abs(incomes.get(0).getMoney()); } } map1.put("rakeMoney",rakeMoney);//抽成 map1.put("thankYouFee", null != orderPrivateCar.getThankYouFee() ? orderPrivateCar.getThankYouFee() : 0);//感谢费 map1.put("returnMoney", 0);//超时退款金额 } break; case 2: OrderTaxi orderTaxi = orderTaxiService.selectById(map.get("incomeId").toString()); if(null != orderTaxi){ List incomes1 = incomeService.queryData(1, null, 2, orderTaxi.getId(), 2); map1.put("travelMoney", null != orderTaxi.getTravelMoney() ? orderTaxi.getTravelMoney() : 0);//行程费 map1.put("parkMoney", null != orderTaxi.getParkMoney() ? orderTaxi.getParkMoney() : 0);//停车费 map1.put("tipMoney", null != orderTaxi.getTipMoney() ? orderTaxi.getTipMoney(): 0);//小费 map1.put("roadTollMoney", null != orderTaxi.getRoadTollMoney() ? orderTaxi.getRoadTollMoney() : 0);//过路费 Double rakeMoney=0.0; if(incomes1.size()>0){ if(incomes1.get(0).getMoney()<0){ rakeMoney = Math.abs(incomes1.get(0).getMoney()); } } map1.put("rakeMoney", rakeMoney);//抽成 map1.put("thankYouFee", null != orderTaxi.getThankYouFee() ? orderTaxi.getThankYouFee() : 0);//感谢费 map1.put("returnMoney", 0);//超时退款金额 } break; case 3: OrderCrossCity orderCrossCity = orderCrossCityService.selectById(map.get("incomeId").toString()); if(null != orderCrossCity){ List incomes2 = incomeService.queryData(1, null, 2, orderCrossCity.getId(), 3); map1.put("travelMoney", null != orderCrossCity.getOrderMoney() ? orderCrossCity.getOrderMoney() : 0);//行程费 map1.put("parkMoney", 0);//停车费 map1.put("tipMoney", 0);//小费 map1.put("roadTollMoney", 0);//过路费 Double rakeMoney=0.0; if(incomes2.size()>0){ if(incomes2.get(0).getMoney()<0){ rakeMoney = Math.abs(incomes2.get(0).getMoney()); } } map1.put("rakeMoney", rakeMoney);//抽成 map1.put("thankYouFee", null != orderCrossCity.getThankYouFee() ? orderCrossCity.getThankYouFee() : 0);//感谢费 map1.put("returnMoney", 0);//超时退款金额 } break; case 4: OrderLogistics orderLogistics = orderLogisticsService.selectById(map.get("incomeId").toString()); if(null != orderLogistics){ List incomes3 = incomeService.queryData(1, null, 2, orderLogistics.getId(), 4); map1.put("travelMoney", null != orderLogistics.getTravelMoney() ? orderLogistics.getTravelMoney() : 0);//行程费 map1.put("parkMoney", 0);//停车费 map1.put("tipMoney", null != orderLogistics.getTipMoney() ? orderLogistics.getTipMoney() : 0);//小费 map1.put("roadTollMoney", 0);//过路费 Double rakeMoney=0.0; if(incomes3.size()>0){ if(incomes3.get(0).getMoney()<0){ rakeMoney = Math.abs(incomes3.get(0).getMoney()); } } map1.put("rakeMoney",rakeMoney);//抽成 map1.put("thankYouFee", null != orderLogistics.getThankYouFee() ? orderLogistics.getThankYouFee() : 0);//感谢费 /// 小件物流超时退款 List list1 = incomeService.selectList(new EntityWrapper().eq("userType",2) .eq("orderType",4).eq("type",9) .eq("objectId",orderLogistics.getDriverId()).eq("incomeId",orderLogistics.getId())); double returnMoney = 0; if (ToolUtil.isNotEmpty(list1)){ for (Income income : list1) { returnMoney += income.getMoney(); } } map1.put("returnMoney", BigDecimal.valueOf(returnMoney).setScale(2,BigDecimal.ROUND_HALF_UP)); } break; case 5: OrderLogistics orderLogistics1 = orderLogisticsService.selectById(map.get("incomeId").toString()); if(null != orderLogistics1){ List incomes4 = incomeService.queryData(1, null, 2, orderLogistics1.getId(), 5); map1.put("travelMoney", null != orderLogistics1.getTravelMoney() ? orderLogistics1.getTravelMoney() : 0);//行程费 map1.put("parkMoney", 0);//停车费 map1.put("tipMoney", orderLogistics1.getTipMoney());//小费 map1.put("roadTollMoney", 0);//过路费 Double rakeMoney=0.0; if(incomes4.size()>0){ if(incomes4.get(0).getMoney()<0){ rakeMoney = Math.abs(incomes4.get(0).getMoney()); } } map1.put("rakeMoney",rakeMoney);//抽成 map1.put("thankYouFee", null != orderLogistics1.getThankYouFee() ? orderLogistics1.getThankYouFee() : 0);//感谢费 /// 小件物流超时退款 List list1 = incomeService.selectList(new EntityWrapper().eq("userType",2) .eq("orderType",5).eq("type",9) .eq("objectId",orderLogistics1.getDriverId()).eq("incomeId",orderLogistics1.getId())); double returnMoney = 0; if (ToolUtil.isNotEmpty(list1)){ for (Income income : list1) { returnMoney += income.getMoney(); } } map1.put("returnMoney", BigDecimal.valueOf(returnMoney).setScale(2,BigDecimal.ROUND_HALF_UP)); } break; } baseWarpper.setData(map1); data.add(baseWarpper); } return ResultUtil.success(data); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取当前有效的活动列表 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryMyActivity") @ApiOperation(value = "获取当前有效的活动列表", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryMyActivity(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return ResultUtil.success(driverService.queryMyActivity(uid, new Date())); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取历史活动列表 * @param pageNum * @param size * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryHistoryActivity") @ApiOperation(value = "获取历史活动列表", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryHistoryActivity(Integer pageNum, Integer size, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List> list = driverService.queryHistory(uid, pageNum, size); return ResultUtil.success(list); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取历史日期中的活动内容 * @param time * @param request * @return */ @ResponseBody @PostMapping("/api/driver/queryHistoryActivityInfo") @ApiOperation(value = "获取历史日期中的活动内容", tags = {"司机端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "查询的给定日期", name = "time", required = true, dataType = "string"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil queryHistoryActivityInfo(String time, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); List activityWarppers = driverService.queryMyActivity(uid, sdf.parse(time)); return ResultUtil.success(activityWarppers); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 工号登录(仅出租车) * @param jobNum * @return */ @ResponseBody @PostMapping("/base/driver/loginByJobNumber") @ApiOperation(value = "工号登录", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "工号", name = "jobNum", required = true, dataType = "String"), }) public ResultUtil loginByJobNumber(String jobNum){ try { return driverService.loginByJobNumber(jobNum); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 身份证号码登录 * @param identification * @return */ @ResponseBody @PostMapping("/base/driver/loginByIdentification") @ApiOperation(value = "身份证号码登录", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "身份证号码", name = "identification", required = true, dataType = "String"), }) public ResultUtil loginByIdentification(String identification){ try { return driverService.loginByIdentification(identification); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 出租车资格证号码登录 * @param taxiAptitudeCard * @return */ @ResponseBody @PostMapping("/base/driver/loginByTaxiAptitudeCard") @ApiOperation(value = "出租车资格证号登录", tags = {"司机端-登录"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "出租车资格证号", name = "taxiAptitudeCard", required = true, dataType = "String"), }) public ResultUtil loginByTaxiAptitudeCard(String taxiAptitudeCard){ try { return driverService.loginByTaxiAptitudeCard(taxiAptitudeCard); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 验证登录密码是否有效 * @param password * @param request * @return */ @ResponseBody @PostMapping("/api/driver/verificationPassword") @ApiOperation(value = "验证登录密码是否有效", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "登录密码", name = "password", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil verificationPassword(String password, HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if(null == driverId){ return ResultUtil.tokenErr(); } return driverService.verificationPassword(password, driverId); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取省市区3级联动 * @return */ @ResponseBody @GetMapping("/base/driver/getRegion") @ApiOperation(value = "获取省市区3级联动", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ }) public ResultUtil> getRegion(){ try { List regions = regionMapper.selectList(null); List regionList = regions.stream().filter(e -> e.getParentId() == 0).collect(Collectors.toList()); for (Region region : regionList) { region.setTire(1); List regionList1 = regions.stream().filter(e -> e.getParentId().equals(region.getId())).collect(Collectors.toList()); for (Region region1 : regionList1) { region1.setTire(2); List regionList2 = regions.stream().filter(e -> e.getParentId().equals(region1.getId())).collect(Collectors.toList()); region1.setChildren(regionList2); } region.setChildren(regionList1); } return ResultUtil.success(regionList); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @ResponseBody @GetMapping("/base/driver/getCompany") @ApiOperation(value = "通过区code获取服务商", tags = {"司机端-注册"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "区code", name = "areaCode", required = true, dataType = "String"), @ApiImplicitParam(value = "name", name = "name", required = false, dataType = "String"), }) public ResultUtil> getCompany(String areaCode,String name){ try { ArrayList companyVos = new ArrayList<>(); List companyCities = companyCityService.selectList(new EntityWrapper().eq("areaCode", areaCode).eq("state", 1)); if(companyCities.isEmpty()){ return ResultUtil.success(companyVos); } Wrapper in = new EntityWrapper().ne("type", 1).ne("flag", 3).in("id", companyCities.stream().map(CompanyCity::getCompanyId).collect(Collectors.toList())); if(ToolUtil.isNotEmpty( name)){ in.like("name", name); } List companies = companyService.selectList(in); for (Company company : companies) { CompanyVo companyVo = new CompanyVo(company.getId(), company.getName()); companyVos.add(companyVo); } return ResultUtil.success(companyVos); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 设置提现密码 * @param withdrawPassword * @param request * @return */ @ResponseBody @PostMapping("/api/driver/setWithdrawPassword") @ApiOperation(value = "设置提现密码", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "提现密码", name = "withdrawPassword", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil setWithdrawPassword(String withdrawPassword, HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if(null == driverId){ return ResultUtil.tokenErr(); } return driverService.setWithdrawPassword(withdrawPassword, driverId); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 验证提现密码是否有效 * @param withdrawPassword * @param request * @return */ @ResponseBody @PostMapping("/api/driver/verificationWithdrawPassword") @ApiOperation(value = "验证提现密码是否有效", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "提现密码", name = "withdrawPassword", required = true, dataType = "String"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil verificationWithdrawPassword(String withdrawPassword, HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if(null == driverId){ return ResultUtil.tokenErr(); } return driverService.verificationWithdrawPassword(withdrawPassword, driverId); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 退出登录 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/loginOut") @ApiOperation(value = "退出登录", tags = {"司机端-车载端"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil loginOut(HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if(null == driverId){ return ResultUtil.tokenErr(); } return driverService.loginOut(driverId); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @Autowired private ITimeOutAppealService appealService; /** * 历史申诉 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/appealHistory") @ApiOperation(value = "历史申诉", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> appealHistory(Integer pageNum, Integer size, HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if(null == driverId){ return ResultUtil.tokenErr(); } List> list = appealService.selectMaps(new EntityWrapper().eq("driverId",driverId).orderBy("id",false).last("limit " + (pageNum-1)*size+ "," + pageNum*size)); for (Map map : list) { OrderLogistics orderLogistics = orderLogisticsService.selectById(map.get("orderId").toString()); map.put("timeOutMoney",orderLogistics.getTimeOutMoney()); map.put("travelTime",DateUtil.getTimes(orderLogistics.getTravelTime())); map.put("endServiceTime",DateUtil.getTimes(orderLogistics.getEndServiceTime())); map.put("timeOut", DateUtil.CalTime(DateUtil.getTime(orderLogistics.getEndServiceTime()),DateUtil.getTime(orderLogistics.getArriveTimeExpect()))); map.put("createTime",DateUtil.getTimeMunite((Date) map.get("createTime"))); if (ToolUtil.isNotEmpty(map.get("dealTime"))){ map.put("dealTime",DateUtil.getTimeMunite((Date) map.get("dealTime"))); }else { map.put("dealTime",""); } } return ResultUtil.success(AppealWrapper.getAppealListWrapper(list)); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } @Autowired private WeChatUtil weChatUtil; @ResponseBody @PostMapping("/api/driver/getDriverCode") @ApiOperation(value = "获取司机端的二维码", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil getDriverCode(HttpServletRequest request) { try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } Driver driver = driverService.selectById(driverId); if (driver != null) { String fileName = driver.getQrCode(); if (fileName == null || "".equals(fileName)) { String appletPath = "pages/home/scanPage/scanPage"; //HttpURLConnection httpURLConnection = weChatUtil.getwxacodeunlimit(appletPath, "d=" + driverId + "&k=" + 0, "release",driverId); InputStream inputStream = weChatUtil.getwxacodeunlimit(appletPath, "driverId=" + driverId, "release"); if (inputStream != null) { // 上传文件目录 fileName = UUID.randomUUID().toString() + ".png"; String fileSavePath = gunsProperties.getFileUploadPath() + "img\\"; FileUtil.writeFromStream(inputStream, fileName); String pictureName = gunsProperties.getPictureServerAddress() + "img/" + fileName; // fileName = OssUploadUtil.ossUploadByStream(driverId, inputStream); System.out.println(pictureName); driver.setQrCode(pictureName); driverService.updateById(driver); } } return ResultUtil.success(fileName); } return ResultUtil.runErr(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 注销账号 * @param request * @return */ @ResponseBody @PostMapping("/api/driver/cancellation") @ApiOperation(value = "注销账号", tags = {"司机端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil cancellation(HttpServletRequest request){ try { Integer driverId = driverService.getUserIdFormRedis(request); if (null == driverId) { return ResultUtil.tokenErr(); } Driver driver = driverService.selectById(driverId); driver.setAuthState(3); driverService.updateById(driver); //开始验证当前账号是否在别处登录 String value = (String) redisTemplate.opsForValue().get("DRIVER_" + driverId); if (ToolUtil.isNotEmpty(value)) {//将另外设备上的强迫下线 //开始清除redis中无效的数据 String key = (String) redisTemplate.opsForValue().get("DRIVER_" + driver.getPhone()); redisTemplate.delete(key);//删除个人信息数据 redisTemplate.delete("DRIVER_" + driver.getPhone());//删除后台冻结相关缓存 redisTemplate.delete("DRIVER_" + driverId);//清除存储的token } return ResultUtil.success(); } catch (Exception e) { e.printStackTrace(); return ResultUtil.runErr(); } } // @ResponseBody // @RequestMapping(value = "/base/driver/uploadImg", method = RequestMethod.POST) // @ApiOperation(value = "上传图片", tags = {"司机端-注册"}, notes = "") // public ResultUtil uploadImg(MultipartFile file) { // try { // String bucketName = "grjy_test"; // Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName); // if (null == grjyTest) { // //创建桶 // Boolean bucket = NCOSSUtil.createBucket(bucketName); // if (!bucket) { // return ResultUtil.error("创建存储桶失败"); // } // //设置桶策略 // String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"]" + // ",\"Effect\":\"Allow\",\"Resource\":[\"" + bucketName + "\"/*],\"Principal\":{*}}]}"; // Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText); // if (!bucketPolicy) { // return ResultUtil.error("设置桶策略失败"); // } // } // //上传对象 // String key = "image/driver/" + UUID.randomUUID().toString() + ".png"; // String object = NCOSSUtil.putObject(bucketName, key, file.getInputStream()); // if (null == object) { // return ResultUtil.error("上传图片失败"); // } // // return ResultUtil.success("http://" + QianYunTongProperties.endPoint + "/" + key); // } catch (Exception e) { // e.printStackTrace(); // return ResultUtil.runErr(); // } // } }