Compare commits
3 Commits
318bf0a8f5
...
4f6878f37e
Author | SHA1 | Date |
---|---|---|
|
4f6878f37e | 2 years ago |
|
0740b9f299 | 2 years ago |
|
b505d01cc0 | 2 years ago |
@ -0,0 +1,16 @@
|
|||||||
|
package com.internal.contant;
|
||||||
|
|
||||||
|
|
||||||
|
public class DriverCarConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 司机状态绑定
|
||||||
|
*/
|
||||||
|
public static final int DRIVER_CAR_BIND = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 司机状态解绑
|
||||||
|
*/
|
||||||
|
public static final int DRIVER_CAR_UNBIND = 2;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.internal.util;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class CommonUtils {
|
||||||
|
|
||||||
|
public static LocalDateTime getLocalDateTimeNow(){
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.now();
|
||||||
|
return localDateTime;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.taxi.servicedriveruser.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.internal.contant.DriverCarConstant;
|
||||||
|
import com.internal.dto.DriverCarBindingRelationship;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.util.CommonUtils;
|
||||||
|
import com.taxi.servicedriveruser.service.DriverCarBindingRelationshipService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author author
|
||||||
|
* @since 2023-04-28
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/driver-car-binding-relationship")
|
||||||
|
public class DriverCarBindingRelationshipController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DriverCarBindingRelationshipService driverCarBindingRelationshipService;
|
||||||
|
|
||||||
|
@PostMapping("/bind")
|
||||||
|
public ResponseResult bind(@RequestBody DriverCarBindingRelationship driverCarBindingRelationship){
|
||||||
|
|
||||||
|
return driverCarBindingRelationshipService.bind(driverCarBindingRelationship);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/unbind")
|
||||||
|
public ResponseResult unbind(@RequestBody DriverCarBindingRelationship driverCarBindingRelationship){
|
||||||
|
|
||||||
|
return driverCarBindingRelationshipService.unbind(driverCarBindingRelationship);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.taxi.servicedriveruser.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.internal.dto.DriverCarBindingRelationship;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author author
|
||||||
|
* @since 2023-04-28
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface DriverCarBindingRelationshipMapper extends BaseMapper<DriverCarBindingRelationship> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,25 @@
|
|||||||
package com.taxi.servicedriveruser.service;
|
package com.taxi.servicedriveruser.service;
|
||||||
|
|
||||||
|
import com.internal.dto.Car;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.taxi.servicedriveruser.mapper.CarMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CarService {
|
public class CarService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarMapper carMapper;
|
||||||
|
|
||||||
|
|
||||||
|
public ResponseResult addCar(Car car) {
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.now();
|
||||||
|
car.setGmtCreate(localDateTime);
|
||||||
|
car.setGmtModified(localDateTime);
|
||||||
|
carMapper.insert(car);
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.taxi.servicedriveruser.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.internal.contant.CommonStatusEnum;
|
||||||
|
import com.internal.contant.DriverCarConstant;
|
||||||
|
import com.internal.dto.DriverCarBindingRelationship;
|
||||||
|
import com.internal.dto.ResponseResult;
|
||||||
|
import com.internal.util.CommonUtils;
|
||||||
|
import com.taxi.servicedriveruser.mapper.DriverCarBindingRelationshipMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import javax.print.attribute.standard.NumberUp;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author author
|
||||||
|
* @since 2023-04-28
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DriverCarBindingRelationshipService{
|
||||||
|
@Autowired
|
||||||
|
private DriverCarBindingRelationshipMapper driverCarBindingRelationshipMapper;
|
||||||
|
|
||||||
|
public ResponseResult bind(@RequestBody DriverCarBindingRelationship driverCarBindingRelationship){
|
||||||
|
//查询条件
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq("driver_id",driverCarBindingRelationship.getDriverId());
|
||||||
|
queryWrapper.eq("car_id",driverCarBindingRelationship.getCarId());
|
||||||
|
//校验数据
|
||||||
|
int count = driverCarBindingRelationshipMapper.selectCount(queryWrapper);
|
||||||
|
if(count == 1 ){
|
||||||
|
driverCarBindingRelationship = driverCarBindingRelationshipMapper.selectOne(queryWrapper);
|
||||||
|
if(driverCarBindingRelationship != null && DriverCarConstant.DRIVER_CAR_BIND == driverCarBindingRelationship.getBindState()) {//已经绑定
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.DRIVER_CAR_BIND_EXISTS);
|
||||||
|
}else if(driverCarBindingRelationship != null && DriverCarConstant.DRIVER_CAR_UNBIND == driverCarBindingRelationship.getBindState()){//更新数据库绑定状态
|
||||||
|
driverCarBindingRelationship.setBindState(DriverCarConstant.DRIVER_CAR_BIND);
|
||||||
|
driverCarBindingRelationshipMapper.updateById(driverCarBindingRelationship);
|
||||||
|
}
|
||||||
|
}else if(count > 1){//排除数据库存在脏数据
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.FAIL);
|
||||||
|
}else{
|
||||||
|
//司机已经绑定
|
||||||
|
queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq("driver_id",driverCarBindingRelationship.getDriverId());
|
||||||
|
queryWrapper.eq("bind_state",DriverCarConstant.DRIVER_CAR_BIND );
|
||||||
|
count = driverCarBindingRelationshipMapper.selectCount(queryWrapper);
|
||||||
|
if(count > 0){
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.DRIVER_CAR_BIND_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq("car_id",driverCarBindingRelationship.getCarId());
|
||||||
|
queryWrapper.eq("bind_state",DriverCarConstant.DRIVER_CAR_BIND );
|
||||||
|
count = driverCarBindingRelationshipMapper.selectCount(queryWrapper);
|
||||||
|
if(count > 0){
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.DRIVER_CAR_BIND_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增数据,并设置绑定状态
|
||||||
|
driverCarBindingRelationship.setBindingTime(CommonUtils.getLocalDateTimeNow() );
|
||||||
|
driverCarBindingRelationship.setBindState(DriverCarConstant.DRIVER_CAR_BIND);
|
||||||
|
driverCarBindingRelationshipMapper.insert(driverCarBindingRelationship);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseResult unbind(@RequestBody DriverCarBindingRelationship driverCarBindingRelationship){
|
||||||
|
Map<String, Object> queryMap = new HashMap<>();
|
||||||
|
queryMap.put("driver_id",driverCarBindingRelationship.getDriverId());
|
||||||
|
queryMap.put("car_id",driverCarBindingRelationship.getCarId());
|
||||||
|
queryMap.put("bind_state",DriverCarConstant.DRIVER_CAR_BIND );
|
||||||
|
List<DriverCarBindingRelationship> list = driverCarBindingRelationshipMapper.selectByMap(queryMap);
|
||||||
|
int count = list.size();
|
||||||
|
if(count == 1){
|
||||||
|
driverCarBindingRelationship = list.get(0);
|
||||||
|
driverCarBindingRelationship.setUnBindingTime(CommonUtils.getLocalDateTimeNow() );
|
||||||
|
driverCarBindingRelationship.setBindState(DriverCarConstant.DRIVER_CAR_UNBIND);
|
||||||
|
driverCarBindingRelationshipMapper.updateById(driverCarBindingRelationship);
|
||||||
|
}else if(count > 1){//排除数据库存在脏数据
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.FAIL);
|
||||||
|
}else if(list.isEmpty()){
|
||||||
|
return ResponseResult.fail(CommonStatusEnum.DRIVER_CAR_BIND_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue