package com.stylefeng.guns.modular.system.controller.specialTrain; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.mapper.EntityWrapper; 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.shiro.ShiroKit; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.dao.OrderCancelMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; 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.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.ui.Model; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Resource; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.*; /** * 专车订单控制器 * * @author fengshuonan * @Date 2020-09-02 17:28:59 */ @Controller @RequestMapping("/tOrderPrivateCar") public class TOrderPrivateCarController extends BaseController { private String PREFIX = "/system/tOrderPrivateCar/"; @Autowired private ITOrderPrivateCarService tOrderPrivateCarService; @Autowired private ITServerCarmodelService tServerCarmodelService; @Autowired private ITOrderPositionService tOrderPositionService; @Autowired private ITDriverService tDriverService; @Resource private OrderCancelMapper orderCancelMapper; @Value("${filePath}") private String filePath; /** * 跳转到专车订单首页 */ @RequestMapping("") public String index(Model model) { //服务专车车型 List carmodelList = tServerCarmodelService.selectList(new EntityWrapper().eq("type", 1).eq("state", 1)); model.addAttribute("carmodelList",carmodelList); return PREFIX + "tOrderPrivateCar.html"; } /** * 跳转到修改专车订单 */ @RequestMapping("/tOrderPrivateCar_orderDetail/{tOrderPrivateCarId}") public String tOrderPrivateCarUpdate(@PathVariable Integer tOrderPrivateCarId, Model model) { Map item = tOrderPrivateCarService.getPrivateCarOrderDetailById(tOrderPrivateCarId); model.addAttribute("item",item); return PREFIX + "tOrderPrivateCar_orderDetail.html"; } /** * 跳转到出租车订单轨迹页面 */ @RequestMapping("/tOrderPrivateCar_trajectory/{tOrderPrivateCarId}") public String tOrderTaxi_trajectory(@PathVariable Integer tOrderPrivateCarId, Model model) { model.addAttribute("tOrderPrivateCarId",tOrderPrivateCarId); return PREFIX + "tOrderPrivateCar_trajectory.html"; } /** * 获取专车订单列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime, String orderNum, Integer orderSource, String userName, String userPhone, String passengers, String passengersPhone, Integer serverCarModelId, 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(tOrderPrivateCarService.getPrivateCarOrderList(page,beginTime,endTime,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),orderNum,orderSource,userName,userPhone,passengers,passengersPhone,serverCarModelId,driver,state)); return super.packForBT(page); } private ResultUtil resultUtil; /** * 获取订单轨迹 * @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", 1).eq("orderId", orderDetailId).orderBy("insertTime")); /*if(list.size() == 0){ return ResultUtil.error("该订单没有运行轨迹"); }*/ //将数据存储到文件中 File file = new File(filePath + orderDetailId + "_1.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 = "/cancel") @ResponseBody public Object cancel(@RequestParam Integer tOrderPrivateCarId) { TOrderPrivateCar tOrderPrivateCar = tOrderPrivateCarService.selectById(tOrderPrivateCarId); //修改之前司机状态 -- 空闲 if(null != tOrderPrivateCar.getDriverId()){ TDriver driver = tDriverService.selectById(tOrderPrivateCar.getDriverId()); // driver.setState(2); tDriverService.updateById(driver); } tOrderPrivateCar.setState(10); tOrderPrivateCarService.updateById(tOrderPrivateCar); OrderCancel orderCancel = new OrderCancel(); orderCancel.setOrderId(tOrderPrivateCarId); orderCancel.setOrderType(1); orderCancel.setReason("平台取消订单"); orderCancel.setRemark("平台取消订单"); orderCancel.setUserType(2); orderCancel.setState(2); orderCancel.setInsertTime(new Date()); orderCancelMapper.insert(orderCancel); //增加推送 Map map = new HashMap<>(); map.put("id", tOrderPrivateCar.getId().toString()); map.put("orderType", "1"); String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map); System.out.println("专车取消:【orderId="+tOrderPrivateCar.getId().toString()+"】,调用接口:"+result); return SUCCESS_TIP; } /** * 删除专车订单 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tOrderPrivateCarId) { TOrderPrivateCar tOrderPrivateCar = tOrderPrivateCarService.selectById(tOrderPrivateCarId); tOrderPrivateCar.setIsDelete(2); tOrderPrivateCarService.updateById(tOrderPrivateCar); return SUCCESS_TIP; } }