package com.stylefeng.guns.modular.system.controller.taxi; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.common.constant.factory.PageFactory; import com.stylefeng.guns.core.log.LogObjectHolder; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.model.TDriver; import com.stylefeng.guns.modular.system.model.TOrderPosition; import com.stylefeng.guns.modular.system.model.TOrderTaxi; import com.stylefeng.guns.modular.system.service.ITDriverService; import com.stylefeng.guns.modular.system.service.ITOrderPositionService; import com.stylefeng.guns.modular.system.service.ITOrderTaxiService; import com.stylefeng.guns.modular.system.util.HttpRequestUtil; import com.stylefeng.guns.modular.system.util.PushURL; import com.stylefeng.guns.modular.system.util.ResultUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 出租车订单控制器 * * @author fengshuonan * @Date 2020-06-08 10:25:55 */ @Controller @RequestMapping("/tOrderTaxi") public class TOrderTaxiController extends BaseController { private String PREFIX = "/system/tOrderTaxi/"; @Autowired private ITOrderTaxiService tOrderTaxiService; @Autowired private ITOrderPositionService tOrderPositionService; @Autowired private ITDriverService tDriverService; @Value("${filePath}") private String filePath; private ResultUtil resultUtil; /** * 跳转到出租车订单首页 */ @RequestMapping("") public String index() { return PREFIX + "tOrderTaxi.html"; } /** * 跳转到添加出租车订单 */ @RequestMapping("/tOrderTaxi_add") public String tOrderTaxiAdd() { return PREFIX + "tOrderTaxi_add.html"; } /** * 跳转到修改出租车订单 */ @RequestMapping("/tOrderTaxi_update/{tOrderTaxiId}") public String tOrderTaxiUpdate(@PathVariable Integer tOrderTaxiId, Model model) { Map tOrderTaxi = tOrderTaxiService.getTaxiOrderDetailById(tOrderTaxiId); model.addAttribute("item",tOrderTaxi); LogObjectHolder.me().set(tOrderTaxi); return PREFIX + "tOrderTaxi_edit.html"; } /** * 跳转到改派出租车订单 */ @RequestMapping("/tOrderTaxi_changeOrder/{tOrderTaxiId}") public String tOrderTaxi_changeOrder(@PathVariable Integer tOrderTaxiId, Model model) { TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId); model.addAttribute("item",tOrderTaxi); LogObjectHolder.me().set(tOrderTaxi); return PREFIX + "tOrderTaxi_changeOrder.html"; } /** * 跳转到出租车订单轨迹页面 */ @RequestMapping("/tOrderTaxi_trajectory/{tOrderTaxiId}") public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) { model.addAttribute("tOrderTaxiId",tOrderTaxiId); return PREFIX + "tOrderTaxi_trajectory.html"; } /** * 获取出租车订单列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime, String orderNum, Integer orderSource, String userName, String userPhone, String passengers, String passengersPhone, String driver, Integer state) { String beginTime = null; String endTime = null; if (SinataUtil.isNotEmpty(insertTime)){ String[] timeArray = insertTime.split(" - "); beginTime = timeArray[0]; endTime = timeArray[1]; } Page> page = new PageFactory>().defaultPage(); page.setRecords(tOrderTaxiService.getTaxiOrderList(page,beginTime,endTime,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),orderNum,orderSource,userName,userPhone,passengers,passengersPhone,driver,state)); return super.packForBT(page); } /** * 选择司机列表 */ @RequestMapping(value = "/selectDriver/{orderId}") @ResponseBody public Object selectDriver(@PathVariable Integer orderId, String name, String phone) { TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId); Page> page = new PageFactory>().defaultPage(); page.setRecords(tOrderTaxiService.getCanSelectTaxiDriverList(page,tOrderTaxi.getCompanyId(),name,phone)); return super.packForBT(page); } /** * 获取订单轨迹 * @param orderDetailId * @return */ @ResponseBody @RequestMapping(value = "/getOrderTrack", method = RequestMethod.POST) public ResultUtil getOrderTrack(String orderDetailId){ if(ToolUtil.isNotEmpty(orderDetailId)){ try { // List list = tOrderPositionService.selectList(new EntityWrapper().eq("orderType", 2).eq("orderId", orderDetailId).orderBy("insertTime")); /*if(list.size() == 0){ return ResultUtil.error("该订单没有运行轨迹"); }*/ //将数据存储到文件中 File file = new File(filePath + orderDetailId + "_2.txt"); if(!file.exists()){ return ResultUtil.success(new ArrayList<>()); } //读取文件(字符流) BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8")); //循环取出数据 String str = null; StringBuffer sb = new StringBuffer(); while ((str = in.readLine()) != null) { sb.append(str); } List list = JSONArray.parseArray(sb.toString(), TOrderPosition.class); resultUtil = ResultUtil.success(list); }catch (Exception e){ e.printStackTrace(); resultUtil = ResultUtil.runErr(); } }else { resultUtil = ResultUtil.paranErr(); } return resultUtil; } /** * 删除出租车订单 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tOrderTaxiId) { TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId); tOrderTaxi.setIsDelete(2); tOrderTaxiService.updateById(tOrderTaxi); return SUCCESS_TIP; } /** * 出租车订单改派司机 */ @RequestMapping(value = "/selectDriver") @ResponseBody public Object selectDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) { //修改订单 TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId); //修改之前司机状态 -- 空闲 TDriver oldDriver = tDriverService.selectById(tOrderTaxi.getDriverId()); oldDriver.setState(2); tDriverService.updateById(oldDriver); //查找司机对象 TDriver nowDriver = tDriverService.selectById(driverId); nowDriver.setState(3); tDriverService.updateById(nowDriver); //修改出租车订单 tOrderTaxi.setState(tOrderTaxi.getOldState()); tOrderTaxi.setDriverId(driverId); tOrderTaxi.setCarId(nowDriver.getCarId()); tOrderTaxiService.updateById(tOrderTaxi); //增加推送 Map map = new HashMap<>(); map.put("orderId", tOrderTaxi.getId().toString()); map.put("orderType", "2"); map.put("from", "admin"); String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map); System.out.println("出租车改派:【orderId="+tOrderTaxi.getId().toString()+"】,调用接口:"+result); return SUCCESS_TIP; } /** * 取消出租车订单 */ @RequestMapping(value = "/cancel") @ResponseBody public Object cancel(@RequestParam Integer tOrderTaxiId) { TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId); //修改之前司机状态 -- 空闲 TDriver driver = tDriverService.selectById(tOrderTaxi.getDriverId()); driver.setState(2); tDriverService.updateById(driver); tOrderTaxi.setState(10); tOrderTaxiService.updateById(tOrderTaxi); //增加推送 Map map = new HashMap<>(); map.put("id", tOrderTaxi.getId().toString()); map.put("orderType", "2"); map.put("from", "admin"); String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map); System.out.println("出租车取消:【orderId="+tOrderTaxi.getId().toString()+"】,调用接口:"+result); return SUCCESS_TIP; } /** * 修改出租车订单 */ @RequestMapping(value = "/update") @ResponseBody public Object update(TOrderTaxi tOrderTaxi) { tOrderTaxiService.updateById(tOrderTaxi); return SUCCESS_TIP; } /** * 出租车订单详情 */ @RequestMapping(value = "/detail/{tOrderTaxiId}") @ResponseBody public Object detail(@PathVariable("tOrderTaxiId") Integer tOrderTaxiId) { return tOrderTaxiService.selectById(tOrderTaxiId); } }