| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.supersavedriving.driver.modular.system.dao.DriverWorkMapper; |
| | | import com.supersavedriving.driver.modular.system.model.Driver; |
| | | import com.supersavedriving.driver.modular.system.model.DriverWork; |
| | | import com.supersavedriving.driver.modular.system.model.OrderTransfer; |
| | | import com.supersavedriving.driver.modular.system.model.SystemConfig; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.model.*; |
| | | import com.supersavedriving.driver.modular.system.service.*; |
| | | import com.supersavedriving.driver.modular.system.dao.DriverWorkMapper; |
| | | import com.supersavedriving.driver.modular.system.service.*; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.service.IDriverWorkService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 司机上下班操作记录 |
| | |
| | | @Autowired |
| | | private IOrderTransferService orderTransferService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | |
| | |
| | | @Override |
| | | public ResultUtil driverWork(Integer driverId) throws Exception { |
| | | Driver driver = driverService.selectById(driverId); |
| | | if(ToolUtil.isEmpty(driver.getMerchantNumber())){ |
| | | return ResultUtil.error("请先注册商户号"); |
| | | } |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6)); |
| | | Double num1 = JSON.parseObject(systemConfig.getContent()).getDouble("num1"); |
| | | if(driver.getBalance() == null || driver.getBalance().compareTo(num1) < 0){ |
| | | return ResultUtil.error("账户余额不足,请先充值"); |
| | | } |
| | | systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1)); |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | Integer num5 = jsonObject.getInteger("num5"); |
| | | OrderTransfer orderTransfer = orderTransferService.selectOne(new EntityWrapper<OrderTransfer>().eq("oldDriverId", driverId) |
| | | .eq("status", 1).isNotNull("successTime").orderBy("createTime desc limit 0, 1")); |
| | | if(null != orderTransfer){ |
| | | int i = Double.valueOf((System.currentTimeMillis() - orderTransfer.getSuccessTime().getTime()) / 60000).intValue(); |
| | | if(num5 > i){ |
| | | return ResultUtil.error("暂时还无法上班,请稍后重试"); |
| | | } |
| | | } |
| | | // systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1)); |
| | | // JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | // Integer num5 = jsonObject.getInteger("num5"); |
| | | // OrderTransfer orderTransfer = orderTransferService.selectOne(new EntityWrapper<OrderTransfer>().eq("oldDriverId", driverId) |
| | | // .eq("status", 1).isNotNull("successTime").orderBy("createTime desc limit 0, 1")); |
| | | // if(null != orderTransfer){ |
| | | // int i = Double.valueOf((System.currentTimeMillis() - orderTransfer.getSuccessTime().getTime()) / 60000).intValue(); |
| | | // if(num5 > i){ |
| | | // return ResultUtil.error("暂时还无法上班,请" + (num5 - i) + "分钟后重试"); |
| | | // } |
| | | // } |
| | | |
| | | DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", 1).eq("status", 1)); |
| | | DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driverId).eq("status", 1)); |
| | | if(null != driverWork){ |
| | | return ResultUtil.error("您正在上班中"); |
| | | } |
| | |
| | | driverWork.setWorkTime(new Date()); |
| | | driverWork.setOnlineTime(0L); |
| | | driverWork.setStatus(1); |
| | | this.updateById(driverWork); |
| | | this.insert(driverWork); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil driverOffWork(Integer driverId, Long onlineTime) throws Exception { |
| | | DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", 1).eq("status", 2)); |
| | | if(null != driverWork){ |
| | | return ResultUtil.error("您已下班,不能重复操作"); |
| | | List<Integer> state = Arrays.asList(102, 103, 104, 105, 106, 201, 401); |
| | | int count = orderService.selectCount(new EntityWrapper<Order>().eq("driverId", driverId).eq("status", 1).in("state", state)); |
| | | if(count > 0){ |
| | | return ResultUtil.error("还有未完成的订单"); |
| | | } |
| | | driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", 1).eq("status", 1)); |
| | | DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driverId).eq("status", 1)); |
| | | if(null == driverWork){ |
| | | return ResultUtil.error("您还未上班"); |
| | | } |
| | | driverWork.setOffWorkTime(new Date()); |
| | | driverWork.setOnlineTime(onlineTime); |
| | | driverWork.setOnlineTime(0L); |
| | | String value = redisUtil.getValue("ONLINE" + driverId); |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | Integer online = Integer.valueOf(value.split("_")[0]); |
| | | driverWork.setOnlineTime(online.longValue()); |
| | | } |
| | | driverWork.setStatus(2); |
| | | this.updateById(driverWork); |
| | | Driver driver = driverService.selectById(driverId); |
| | | driver.setServerStatus(1); |
| | | driverService.updateById(driver); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void taskDriverOffWork() { |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6)); |
| | | Double num1 = JSON.parseObject(systemConfig.getContent()).getDouble("num1"); |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("status", 1).lt("balance", num1)); |
| | | for (Driver driver : drivers) { |
| | | DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver.getId()).eq("status", 1)); |
| | | if(null != driverWork){ |
| | | driverWork.setStatus(2); |
| | | driverWork.setOffWorkTime(new Date()); |
| | | this.updateById(driverWork); |
| | | } |
| | | } |
| | | } |
| | | } |