| package com.stylefeng.guns.modular.system.service.impl; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONObject; | 
| 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.system.dao.LineShiftDriverMapper; | 
| import com.stylefeng.guns.modular.system.dao.LineShiftMapper; | 
| import com.stylefeng.guns.modular.system.dao.LineSiteMapper; | 
| import com.stylefeng.guns.modular.system.model.*; | 
| import com.stylefeng.guns.modular.system.service.ILineSiteService; | 
| import com.stylefeng.guns.modular.system.service.IOrderCrossCityService; | 
| import com.stylefeng.guns.modular.system.service.IOrderPrivateCarService; | 
| import com.stylefeng.guns.modular.system.service.IOrderTaxiService; | 
| import com.stylefeng.guns.modular.system.util.RedisUtil; | 
| import com.stylefeng.guns.modular.system.util.SystemException; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import javax.annotation.Resource; | 
| import java.math.BigDecimal; | 
| import java.text.SimpleDateFormat; | 
| import java.util.*; | 
|   | 
|   | 
| @Service | 
| public class LineSiteServiceImpl extends ServiceImpl<LineSiteMapper, LineSite> implements ILineSiteService { | 
|   | 
|     @Resource | 
|     private LineSiteMapper lineSiteMapper; | 
|   | 
|     @Resource | 
|     private LineShiftMapper lineShiftMapper; | 
|   | 
|     @Resource | 
|     private LineShiftDriverMapper lineShiftDriverMapper; | 
|   | 
|     @Autowired | 
|     private RedisUtil redisUtil; | 
|   | 
|     @Autowired | 
|     private IOrderPrivateCarService orderPrivateCarService; | 
|   | 
|     @Autowired | 
|     private IOrderCrossCityService orderCrossCityService; | 
|   | 
|     @Autowired | 
|     private IOrderTaxiService orderTaxiService; | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 根据线路id获取排班数据 | 
|      * @param lineId | 
|      * @param day | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public List<Map<String, Object>> queryDriver(Integer lineId, String day) throws Exception { | 
|         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|         Calendar c = Calendar.getInstance(); | 
|         c.setTime(new Date()); | 
|         c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0); | 
|         c.set(Calendar.MILLISECOND, 0); | 
|         if(c.getTimeInMillis() > sdf.parse(day).getTime()){ | 
|             throw new SystemException("日期不能小于当天"); | 
|         } | 
|         List<Map<String, Object>> list = new ArrayList<>(); | 
|         List<LineShift> lineShifts = lineShiftMapper.selectList(new EntityWrapper<LineShift>().eq("lineId", lineId).eq("state", 1).orderBy("startTime")); | 
|         List<Map<String, Object>> s = lineSiteMapper.queryDriver(lineId, sdf.parse(day), null); | 
|         Calendar calendar = Calendar.getInstance(); | 
|         calendar.setTime(sdf.parse(day)); | 
|         String vehicle = redisUtil.getValue("VEHICLE"); | 
|         List<Integer> integers = new ArrayList<>(); | 
|         if(ToolUtil.isNotEmpty(vehicle)){ | 
|             integers = JSON.parseArray(vehicle).toJavaList(Integer.class); | 
|         } | 
|         for(LineShift lineShift : lineShifts){ | 
|             boolean b = true; | 
|             String[] split = lineShift.getEndTime().split(":"); | 
|             calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|             calendar.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|             if(calendar.getTimeInMillis() < System.currentTimeMillis()){//结束时间小于当前时间不显示 | 
|                 continue; | 
|             } | 
|   | 
|             Map<String, Object> data = new HashMap<>(); | 
|             for(Map<String, Object> map : s){ | 
|                 //先判断司机是否在限制接单范围内 | 
|                 boolean bo = false; | 
|                 for(Integer integer : integers){ | 
|                     if(integer.compareTo(Integer.valueOf(map.get("driverId").toString())) == 0){ | 
|                         bo = true; | 
|                         break; | 
|                     } | 
|                 } | 
|                 if(bo){ | 
|                     continue; | 
|                 } | 
|   | 
|   | 
|                 int i = orderTaxiService.selectCount(new EntityWrapper<OrderTaxi>().eq("driverId", map.get("driverId")).in("state", Arrays.asList(2, 3, 4, 5, 11)).eq("DATE_FORMAT(travelTime, '%Y-%m-%d')", day)); | 
|                 if(i > 0){ | 
|                     continue; | 
|                 } | 
|                 i = orderPrivateCarService.selectCount(new EntityWrapper<OrderPrivateCar>().eq("driverId", map.get("driverId")).in("state", Arrays.asList(2, 3, 4, 5, 11)).eq("DATE_FORMAT(travelTime, '%Y-%m-%d')", day)); | 
|                 if(i > 0){ | 
|                     continue; | 
|                 } | 
|                 List<OrderCrossCity> driverId1 = orderCrossCityService.queryListOrder(Integer.valueOf(map.get("driverId").toString()), lineShift.getId(), Arrays.asList(5), day); | 
|                 if(driverId1.size() > 0){ | 
|                     continue; | 
|                 } | 
|                 if(Integer.valueOf(map.get("laveSeat").toString()) <= 0){ | 
|                     continue; | 
|                 } | 
|                 if(lineShift.getId().intValue() == Integer.valueOf(map.get("lineShiftId").toString()).intValue()){ | 
|                     b = false; | 
|                     String content = map.get("content").toString(); | 
|                     JSONObject jsonObject = JSON.parseObject(content); | 
|                     map.put("price", jsonObject.getString("num1")); | 
|                     Object o = map.get("evaluate") == null ? 0 : map.get("evaluate"); | 
|                     map.put("evaluate", new BigDecimal(o.toString()).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); | 
|                     data = map; | 
|                     list.add(data); | 
|                 } | 
|             } | 
|             if(b){ | 
|                 data.put("id", lineShift.getId()); | 
|                 data.put("startTime", lineShift.getStartTime()); | 
|                 list.add(data); | 
|             } | 
|         } | 
|         return list; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 根据司机排班数据id获取数据(剩余座位号和总座位数) | 
|      * @param id | 
|      * @return | 
|      * @throws Exception | 
|      */ | 
|     @Override | 
|     public Map<String, Object> querySeat(Integer id) throws Exception { | 
|         Map<String, Object> map = new HashMap<>(); | 
|         LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(id); | 
|         map.put("totalNumber", lineShiftDriver.getTotalSeat()); | 
|         map.put("number", lineShiftDriver.getLaveSeat()); | 
|         map.put("content", lineShiftDriver.getLaveSeatNumber()); | 
|         return map; | 
|     } | 
| } |