| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.api.OrderController; |
| | | import com.stylefeng.guns.modular.crossCity.dao.LineShiftDriverMapper; |
| | | import com.stylefeng.guns.modular.crossCity.model.LineShiftDriver; |
| | | 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.IOrderLogisticsSpreadService; |
| | | import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; |
| | | import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; |
| | | import com.stylefeng.guns.modular.system.dao.CarModelMapper; |
| | | import com.stylefeng.guns.modular.system.dao.DispatchMapper; |
| | | import com.stylefeng.guns.modular.system.dao.ReassignMapper; |
| | | import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper; |
| | |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | @Autowired |
| | | private IReassignService reassignService; |
| | | |
| | | @Resource |
| | | private LineShiftDriverMapper lineShiftDriverMapper; |
| | | |
| | | @Autowired |
| | | private OrderController orderController; |
| | | |
| | | @Resource |
| | | private CarModelMapper carModelMapper; |
| | | |
| | | @Autowired |
| | | private ICarService carService; |
| | | |
| | | |
| | | /** |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil saveData_(Reassign reassign, String orderIds, Integer uid, Integer type) throws Exception { |
| | | public ResultUtil saveData_(Reassign reassign, String orderIds, Integer uid, Integer type,Integer newDriverId) throws Exception { |
| | | type = null == type ? 2 : type;//现目前微信只支持小程序支付 |
| | | String content = reassign.getRemark(); |
| | | if(ToolUtil.isNotEmpty(content)){ |
| | |
| | | ids += reassign.getId() + ","; |
| | | } |
| | | ids = ids.substring(0, ids.length() - 1); |
| | | systemNoticeService.addSystemNotice(2, "您的改派申请已成功提交,我们会尽快为你处理!", uid); |
| | | |
| | | |
| | | if(newDriverId == null) { |
| | | systemNoticeService.addSystemNotice(2, "您的改派申请已成功提交,我们会尽快为你处理!", uid); |
| | | //开始支付 |
| | | if(null != reassign.getPayType()){ |
| | | if(reassign.getPayType() == 1){//微信支付 |
| | |
| | | } |
| | | } |
| | | } |
| | | return resultUtil; |
| | | }else { |
| | | //开始支付 |
| | | if (null != reassign.getPayType()) { |
| | | if (reassign.getPayType() == 1) {//微信支付 |
| | | String[] split1 = ids.split(","); |
| | | // Map<String, String> map = icbcPayUtil.placeAnOrder(ids + "_3", 9, 5, uid.toString(), "改派订单", totalMoney, callbackPath + "/base/wxReassign", "", type, driver.getAppletsOpenId()); |
| | | // if(map.get("code").equals("200")){ |
| | | // for(String id : split1){ |
| | | // paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 1, aDouble, map.get("order_id"), 1);//添加预支付数据 |
| | | // } |
| | | // resultUtil = ResultUtil.success(map.get("data")); |
| | | // }else{ |
| | | // resultUtil = ResultUtil.error(map.get("msg"), ""); |
| | | // } |
| | | } |
| | | if (reassign.getPayType() == 2) {//支付宝 |
| | | String[] split1 = ids.split(","); |
| | | // Map<String, String> map = icbcPayUtil.placeAnOrder(ids + "_3", 10, 5, uid.toString(), "改派订单", totalMoney, callbackPath + "/base/aliReassign", "", 2, ""); |
| | | // if(map.get("code").equals("200")){ |
| | | // for(String id : split1){ |
| | | // paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 2, aDouble, map.get("order_id"), 1);//添加预支付数据 |
| | | // } |
| | | // resultUtil = ResultUtil.success(map.get("data")); |
| | | // }else{ |
| | | // resultUtil = ResultUtil.error(map.get("msg"), ""); |
| | | // } |
| | | } |
| | | if (reassign.getPayType() == 3) {//余额 |
| | | for (String id : split) { |
| | | Reassign query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 1); |
| | | query.setState(2); |
| | | query.setPayTime(new Date()); |
| | | reassignMapper.updateById(query); |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(uid, "司机改派支付", aDouble, 2, 1, 2, 3, Integer.valueOf(id)); |
| | | } |
| | | Double balance = driver.getBalance(); |
| | | if (null == balance || balance < totalMoney) { |
| | | throw new SystemException("账户余额不足"); |
| | | } |
| | | driver.setBalance(new BigDecimal(balance).subtract(new BigDecimal(totalMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | |
| | | |
| | | //修改改派通知状态 |
| | | for (String id : split) { |
| | | OrderCrossCity orderCrossCity = orderCrossCityService.selectById(id); |
| | | orderCrossCity.setOldState(orderCrossCity.getState()); |
| | | orderCrossCity.setState(11); |
| | | orderCrossCity.setReassignNotice(2); |
| | | orderCrossCityService.updateById(orderCrossCity); |
| | | |
| | | //添加已收入明细 |
| | | incomeService.saveData(1, orderCrossCity.getCompanyId(), 4, orderCrossCity.getId(), 3, reassign.getMoney()); |
| | | } |
| | | systemNoticeService.addSystemNotice(2, "您已使用余额成功支付改派申请费用!", uid); |
| | | //开始推送调度单 |
| | | // Map<String, String> map = new HashMap<>(); |
| | | // map.put("orderId", reassign.getOrderId().toString()); |
| | | // map.put("orderType", reassign.getOrderType().toString()); |
| | | // List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1); |
| | | // for (Dispatch dispatch : dispatches) { |
| | | // jgPushUtil.push(2, "有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId()); |
| | | // } |
| | | |
| | | //将所有改派单都给新的司机 |
| | | String[] split1 = ids.split(","); |
| | | for (String s : split1) { |
| | | selectCrossDriver(Integer.valueOf(s), newDriverId); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | | return resultUtil; |
| | | } |
| | | /** |
| | | * 跨城出行订单改派司机 |
| | | */ |
| | | |
| | | public Object selectCrossDriver(@RequestParam Integer reassign, @RequestParam Integer driverId) { |
| | | //修改原司机信息 |
| | | //修改订单 |
| | | Reassign tReassign = reassignService.selectById(reassign); |
| | | OrderCrossCity tOrderCrossCity = orderCrossCityService.selectById(tReassign.getOrderId()); |
| | | Driver oldDriver = driverService.selectById(tReassign.getOriginalDriverId()); |
| | | LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(tOrderCrossCity.getLineShiftDriverId()); |
| | | lineShiftDriver.setLaveSeat(lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat() ? |
| | | lineShiftDriver.getTotalSeat() : lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber()); |
| | | String seat = ""; |
| | | String[] split = tOrderCrossCity.getSeatNumber().split(","); |
| | | for(String s : split){ |
| | | seat += s + ","; |
| | | } |
| | | seat = lineShiftDriver.getLaveSeatNumber() + "," + seat.substring(0, seat.length() - 1); |
| | | |
| | | //总和大于总座位数的情况 |
| | | if(lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat()){ |
| | | seat = ""; |
| | | for(int i = 1; i <= lineShiftDriver.getTotalSeat(); i++){ |
| | | seat += i + ","; |
| | | } |
| | | seat = seat.substring(0, seat.length() - 1); |
| | | } |
| | | lineShiftDriver.setLaveSeatNumber(seat); |
| | | lineShiftDriverMapper.updateById(lineShiftDriver); |
| | | if(lineShiftDriver.getLaveSeat() >= lineShiftDriver.getTotalSeat()){ |
| | | oldDriver.setState(2); |
| | | driverService.updateById(oldDriver); |
| | | } |
| | | |
| | | //修改新司机数据 |
| | | List<LineShiftDriver> query = lineShiftDriverMapper.queryByDriver(lineShiftDriver.getLineShiftId(), driverId, tOrderCrossCity.getTravelTime()); |
| | | LineShiftDriver lineShiftDriver1 = null; |
| | | |
| | | if(query.size() == 0){ |
| | | // return ResultUtil.error("司机没有预约班次"); |
| | | CarModel carModel = carModelMapper.selectById(carService.selectById(driverService.selectById(driverId).getCarId()).getCarModelId()); |
| | | |
| | | LineShiftDriver lineShiftDriver0 = new LineShiftDriver(); |
| | | lineShiftDriver0.setLineShiftId(lineShiftDriver.getLineShiftId()); |
| | | lineShiftDriver0.setDriverId(driverId); |
| | | lineShiftDriver0.setDay(lineShiftDriver.getDay()); |
| | | lineShiftDriver0.setTotalSeat(carModel.getSeat() - 1); |
| | | lineShiftDriver0.setLaveSeat(carModel.getSeat() - 1); |
| | | lineShiftDriver0.setInserTime(new Date()); |
| | | String seatNumber = ""; |
| | | for(int i = 1; i < carModel.getSeat(); i++){ |
| | | seatNumber += i + ","; |
| | | } |
| | | lineShiftDriver0.setLaveSeatNumber(seatNumber.substring(0, seatNumber.length() - 1)); |
| | | |
| | | Integer insert = lineShiftDriverMapper.insert(lineShiftDriver0); |
| | | lineShiftDriver1 = lineShiftDriver0; |
| | | |
| | | }else { |
| | | lineShiftDriver1 = query.get(0); |
| | | |
| | | } |
| | | if(lineShiftDriver1.getLaveSeat() < tOrderCrossCity.getPeopleNumber()){ |
| | | return ResultUtil.runErr("司机车辆剩余座位数不足"); |
| | | } |
| | | lineShiftDriver1.setLaveSeat(lineShiftDriver1.getLaveSeat() - tOrderCrossCity.getPeopleNumber()); |
| | | String[] split1 = lineShiftDriver1.getLaveSeatNumber().split(","); |
| | | String seat1 = "";//使用 |
| | | String seat2 = "";//未使用 |
| | | for(int i = 0; i < tOrderCrossCity.getPeopleNumber(); i++){ |
| | | seat1 += split1[i] + ","; |
| | | } |
| | | for(int i = tOrderCrossCity.getPeopleNumber(); i < split1.length; i++){ |
| | | seat2 += split1[i] + ","; |
| | | } |
| | | lineShiftDriver1.setLaveSeatNumber(seat2); |
| | | lineShiftDriverMapper.updateById(lineShiftDriver1); |
| | | Driver driver = driverService.selectById(driverId); |
| | | // if(driver.getState() == 1){ |
| | | // return ResultUtil.error("司机还未上班呢"); |
| | | // } |
| | | // if(driver.getState() == 2){ |
| | | // driver.setState(3); |
| | | // } |
| | | |
| | | //修改订单数据 |
| | | tOrderCrossCity.setDriverId(driverId); |
| | | tOrderCrossCity.setCarId(driver.getCarId()); |
| | | tOrderCrossCity.setSeatNumber(seat1); |
| | | tOrderCrossCity.setState(tOrderCrossCity.getOldState()); |
| | | tOrderCrossCity.setLineShiftDriverId(lineShiftDriver1.getId()); |
| | | tOrderCrossCity.setOldState(null); |
| | | tOrderCrossCity.setIsReassign(2); |
| | | try { |
| | | tOrderCrossCity.setOrderNum(orderCrossCityService.getOrderNum(driverId, tOrderCrossCity.getLineShiftDriverId())); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | orderCrossCityService.updateAllColumnById(tOrderCrossCity); |
| | | |
| | | //修改专车改派订单 |
| | | tReassign.setNowDriverId(driverId); |
| | | tReassign.setNowCarId(driver.getCarId()); |
| | | tReassign.setState(3); |
| | | tReassign.setCompleteTime(new Date()); |
| | | reassignService.updateById(tReassign); |
| | | |
| | | //修改收入明细,转给新司机(因为是先支付金额) |
| | | List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", oldDriver.getId()).eq("type", 2).eq("incomeId", tReassign.getOrderId()).eq("orderType", 3)); |
| | | if(incomes.size() > 0){ |
| | | Income income = incomes.get(0); |
| | | income.setObjectId(driverId); |
| | | incomeService.updateById(income); |
| | | |
| | | oldDriver.setBusinessMoney(oldDriver.getBusinessMoney() - income.getMoney()); |
| | | oldDriver.setLaveBusinessMoney(oldDriver.getLaveBusinessMoney() - income.getMoney()); |
| | | oldDriver.setBalance(oldDriver.getBalance()-income.getMoney()); |
| | | |
| | | driver.setBusinessMoney(driver.getBusinessMoney() + income.getMoney()); |
| | | driver.setLaveBusinessMoney(driver.getLaveBusinessMoney() + income.getMoney()); |
| | | driver.setBalance(driver.getBalance()+income.getMoney()); |
| | | |
| | | } |
| | | driverService.updateById(oldDriver); |
| | | driverService.updateById(driver); |
| | | //增加推送 |
| | | // Map<String,String> map = new HashMap<>(); |
| | | // map.put("orderId", tOrderCrossCity.getId().toString()); |
| | | // map.put("orderType", "3"); |
| | | String result = orderController.pushOrderState(tOrderCrossCity.getId(), 3); |
| | | // String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map); |
| | | System.out.println("跨城出行改派:【orderId="+tOrderCrossCity.getId().toString()+"】,调用接口:"+result); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |