xuhy
2023-02-20 d4b9b8b957407b480513f3eaae486ad03dad2082
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.supersavedriving.driver.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
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.SystemConfig;
import com.supersavedriving.driver.modular.system.service.IDriverService;
import com.supersavedriving.driver.modular.system.service.IDriverWorkService;
import com.supersavedriving.driver.modular.system.service.IOrderService;
import com.supersavedriving.driver.modular.system.service.ISystemConfigService;
import com.supersavedriving.driver.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Date;
 
/**
* 司机上下班操作记录
* @author pzb
* @Date 2023/2/15 15:48
*/
@Service
public class DriverWorkServiceImpl extends ServiceImpl<DriverWorkMapper, DriverWork> implements IDriverWorkService {
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private ISystemConfigService systemConfigService;
 
    @Autowired
    private IOrderService orderService;
 
 
 
 
    /**
     * 司机上班操作
     * @param driverId
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil driverWork(Integer driverId) throws Exception {
        Driver driver = driverService.selectById(driverId);
        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));
        JSON.parseObject(systemConfig.getContent()).getDouble("num1");
 
 
        DriverWork driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", 1).eq("status", 1));
        if(null != driverWork){
            return ResultUtil.error("您正在上班中");
        }
        driverWork = new DriverWork();
        driverWork.setDriverId(driverId);
        driverWork.setWorkTime(new Date());
        driverWork.setOnlineTime(0L);
        driverWork.setStatus(1);
        this.updateById(driverWork);
        return ResultUtil.success();
    }
 
 
    /**
     * 司机下班操作
     * @param driverId      司机id
     * @param onlineTime    在线时长(秒)
     * @return
     * @throws Exception
     */
    @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("您已下班,不能重复操作");
        }
        driverWork = this.selectOne(new EntityWrapper<DriverWork>().eq("driverId", 1).eq("status", 1));
        if(null == driverWork){
            return ResultUtil.error("您还未上班");
        }
        driverWork.setOffWorkTime(new Date());
        driverWork.setOnlineTime(onlineTime);
        driverWork.setStatus(2);
        this.updateById(driverWork);
        return ResultUtil.success();
    }
}