| | |
| | | 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.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TOrderResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp; |
| | | import com.stylefeng.guns.modular.system.controller.util.UUIDUtil; |
| | | import com.stylefeng.guns.modular.system.dao.TAppUserMapper; |
| | | import com.stylefeng.guns.modular.system.dao.TBranchOfficeMapper; |
| | | import com.stylefeng.guns.modular.system.dao.TDriverMapper; |
| | |
| | | import com.stylefeng.guns.modular.system.model.TBranchOffice; |
| | | import com.stylefeng.guns.modular.system.model.TDriver; |
| | | import com.stylefeng.guns.modular.system.model.TOrder; |
| | | import com.stylefeng.guns.modular.system.service.ITAppUserService; |
| | | import com.stylefeng.guns.modular.system.service.ITOrderService; |
| | | import com.stylefeng.guns.modular.system.util.DateUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | |
| | | @Service |
| | | public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private TOrderMapper tOrderMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TAppUserMapper tAppUserMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TDriverMapper tDriverMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TBranchOfficeMapper tBranchOfficeMapper; |
| | | |
| | | @Autowired |
| | | private ITAppUserService appUserService; |
| | | |
| | | @Override |
| | | public List<TOrderResp> getOrderList(String createTime, String code, Integer source, String userName, String userPhone, Integer state, String driverName,Integer isException) { |
| | |
| | | // 查询司机当月有效订单数量 |
| | | return tOrderMapper.getValidOrderCount(driverId,orderMoney,month); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil add(TOrder tOrder) { |
| | | String startAddress = tOrder.getStartAddress(); |
| | | String endAddress = tOrder.getEndAddress(); |
| | | String userPhone = tOrder.getUserPhone(); |
| | | int count = this.selectCount(new EntityWrapper<TOrder>().eq("userPhone", userPhone).eq("status", 1).in("state", Arrays.asList(101, 102, 103, 104, 105, 106, 201))); |
| | | if(count > 0){ |
| | | return ResultUtil.error("该用户还有未完成的订单", ""); |
| | | } |
| | | TAppUser tAppUser = appUserService.selectOne(new EntityWrapper<TAppUser>().eq("phone", userPhone).eq("status", 1)); |
| | | if(null != tAppUser){ |
| | | tOrder.setUserId(tAppUser.getId()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(startAddress); |
| | | tOrder.setStartAddress(jsonObject.getString("address")); |
| | | tOrder.setStartLat(jsonObject.getString("lat")); |
| | | tOrder.setStartLng(jsonObject.getString("lon")); |
| | | tOrder.setSource(3); |
| | | if(ToolUtil.isNotEmpty(endAddress)){ |
| | | jsonObject = JSON.parseObject(endAddress); |
| | | tOrder.setEndAddress(jsonObject.getString("address")); |
| | | tOrder.setEndLat(jsonObject.getString("lat")); |
| | | tOrder.setEndLng(jsonObject.getString("lon")); |
| | | } |
| | | tOrder.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3)); |
| | | Double d = 0D; |
| | | if(ToolUtil.isNotEmpty(endAddress)){ |
| | | Map<String, String> distance = MapUtil.getDistance(tOrder.getStartLng() + "," + tOrder.getStartLat(), tOrder.getEndLng() + "," + tOrder.getEndLat(), 1); |
| | | if(null == distance){ |
| | | return ResultUtil.error("获取预估距离出错", ""); |
| | | } |
| | | d = Double.valueOf(distance.get("distance")) / 1000; |
| | | order.setEstimatedMileage(d); |
| | | order.setEstimatedTime(Integer.valueOf(distance.get("duration")) / 60); |
| | | } |
| | | String city = ""; |
| | | District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat()); |
| | | if(null != geocode){ |
| | | WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>() |
| | | .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') ")); |
| | | city = null != weatherCity ? weatherCity.getId().toString() : ""; |
| | | } |
| | | order = getOrderPrice(1, d, 0, order, city); |
| | | order.setState(null == order.getDriverId() ? 101 : 102); |
| | | order.setStatus(1); |
| | | order.setCreateTime(new Date()); |
| | | this.insert(order); |
| | | driverService.updateById(driver); |
| | | //推送状态 |
| | | if(null != order.getDriverId()){ |
| | | pushUtil.pushOrderStatus(uid, 2, order.getId(), order.getStatus()); |
| | | }else{ |
| | | //开始推单 |
| | | Order finalOrder = order; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushOrder(finalOrder); |
| | | } |
| | | }).start(); |
| | | } |
| | | return ResultUtil.success(order.getState() == 102 ? order.getId() : null); |
| | | } |
| | | } |