| | |
| | | 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.alipay.api.internal.util.file.IOUtils; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | 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.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.ALiSendSms; |
| | | 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.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.*; |
| | | 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 javax.servlet.http.HttpSession; |
| | | 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.stream.Collectors; |
| | | |
| | | import static org.bouncycastle.cms.RecipientId.password; |
| | | |
| | | /** |
| | | * 司机控制器 |
| | |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping("") |
| | | @Slf4j |
| | | public class DriverController { |
| | | |
| | | @Resource |
| | |
| | | private ICarService carService; |
| | | |
| | | @Autowired |
| | | private ALiSendSms aLiSendSms; |
| | | private RegionMapper regionMapper; |
| | | |
| | | @Autowired |
| | | private IOrderTaxiService orderTaxiService; |
| | |
| | | |
| | | @Autowired |
| | | private GunsProperties gunsProperties; |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private ICompanyService companyService; |
| | | |
| | | @Autowired |
| | | private ICompanyCityService companyCityService; |
| | | |
| | | @Autowired |
| | | private TDriverPromotionActivityService driverPromotionActivityService; |
| | | |
| | | |
| | | @Autowired |
| | | private QianYunTongConfig qianYunTongConfig; |
| | | |
| | | /** |
| | | * 获取短信验证码 |
| | |
| | | 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<DriverIndexVo> 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<DriverOrderDataVo> queryOrderDataFromDriver(String time,Integer pageNumber,Integer pageSize,HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserIdFormRedis(request); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Page<DriverOrderDataNextVo> 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<DriverOrderMoneyDataVo> queryOrderMoneyFromDriver(String time, Integer pageNumber, Integer pageSize, HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserIdFormRedis(request); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Page<DriverOrderDataNextVo> 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<DriverOrderPromotionDataVo> queryOrderPromotionFromDriver(String time, Integer pageNumber, Integer pageSize, HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserIdFormRedis(request); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Page<DriverOrderDataNextVo> 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<String> 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<TDriverPromotionActivity>() |
| | | .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/person-code") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | }) |
| | | public ResultUtil<HashMap<String, String>> createQRcode(HttpServletRequest request) { |
| | | InputStream inputStream = null; |
| | | OutputStream outputStream = null; |
| | | try { |
| | | Integer uid = driverService.getUserIdFormRedis(request); |
| | | if (null == uid) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Driver driver = driverService.selectById(uid); |
| | | String accessToken=null; |
| | | // 获取调用凭证accessToken |
| | | if(ToolUtil.isEmpty(driver.getShareImg())|| ToolUtil.isEmpty(driver.getShareImg())){ |
| | | accessToken = getAccessToken(); |
| | | } |
| | | String img=driver.getShareImg(); |
| | | int index=0; |
| | | |
| | | if(ToolUtil.isEmpty(driver.getShareImg())) { |
| | | index=1; |
| | | RestTemplate rest = new RestTemplate(); |
| | | String imgUrl = ""; |
| | | String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + accessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("path", "pages/home/home?driverId=" + uid); |
| | | param.put("width", 430); //二维码尺寸 |
| | | MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
| | | HttpEntity requestEntity = new HttpEntity(param, headers); |
| | | ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); |
| | | byte[] result = entity.getBody(); |
| | | inputStream = new ByteArrayInputStream(result); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | // 最后上传生成的文件名 |
| | | String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg"; |
| | | // oss中的文件夹名 |
| | | String objectName = sdf.format(new Date()) + "/" + finalFileName; |
| | | String key = "imgs/management/" + objectName; |
| | | String object = NCOSSUtil.putObject(qianYunTongConfig.getBucketName(), key, inputStream); |
| | | System.out.println(object); |
| | | driver.setShareImg(object); |
| | | img= object; |
| | | } |
| | | |
| | | String urlLink = driver.getShareLink(); |
| | | if(ToolUtil.isEmpty(urlLink)) { |
| | | index=1; |
| | | String url1 = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + accessToken; |
| | | Map<String, Object> 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<String, String> stringStringHashMap = new HashMap<>(); |
| | | stringStringHashMap.put("url_link",urlLink); |
| | | stringStringHashMap.put("img",img); |
| | | |
| | | |
| | | // inputStream = new ByteArrayInputStream(result); |
| | | // |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | // // 最后上传生成的文件名 |
| | | // String finalFileName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + ".jpg"; |
| | | // // oss中的文件夹名 |
| | | // String objectName = sdf.format(new Date()) + "/" + finalFileName; |
| | | // // 上传oss |
| | | //// ossUtil.uploadFile2OSS(inputStream, objectName); |
| | | //// //获取文件的URl地址 |
| | | //// imgUrl = ossUtil.getImgUrl(objectName); |
| | | // log.info("imgUrl: "+imgUrl); |
| | | return ResultUtil.success(stringStringHashMap); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("调用小程序生成微信永久小程序码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 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"); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/queryMyCar") |
| | | @ApiOperation(value = "获取当前车辆及空闲车辆", tags = {"司机端-个人中心"}, notes = "") |
| | | @ApiOperation(value = "获取当前车辆及空闲车辆 新增useState 1使用中 2空闲", tags = {"司机端-个人中心"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | |
| | | |
| | | |
| | | /** |
| | | * 获取省市区3级联动 |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @GetMapping("/base/driver/getRegion") |
| | | @ApiOperation(value = "获取省市区3级联动", tags = {"司机端-注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public ResultUtil<List<Region>> getRegion(){ |
| | | try { |
| | | List<Region> regions = regionMapper.selectList(null); |
| | | List<Region> regionList = regions.stream().filter(e -> e.getParentId() == 0).collect(Collectors.toList()); |
| | | for (Region region : regionList) { |
| | | region.setTire(1); |
| | | List<Region> regionList1 = regions.stream().filter(e -> e.getParentId().equals(region.getId())).collect(Collectors.toList()); |
| | | for (Region region1 : regionList1) { |
| | | region1.setTire(2); |
| | | List<Region> 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"), |
| | | |
| | | }) |
| | | public ResultUtil<List<CompanyVo>> getCompany(String areaCode){ |
| | | try { |
| | | |
| | | ArrayList<CompanyVo> companyVos = new ArrayList<>(); |
| | | List<CompanyCity> companyCities = companyCityService.selectList(new EntityWrapper<CompanyCity>().eq("areaCode", areaCode).eq("state", 1)); |
| | | if(companyCities.isEmpty()){ |
| | | return ResultUtil.success(companyVos); |
| | | } |
| | | List<Company> companies = companyService.selectList(new EntityWrapper<Company>().ne("type", 1).ne("flag", 3).in("id", companyCities.stream().map(CompanyCity::getCompanyId).collect(Collectors.toList()))); |
| | | 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 |