feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.RestaurantBaseInfo
import cn.flightfeather.supervision.domain.entity.VehicleBaseInfo
import cn.flightfeather.supervision.domain.mapper.BaseInfoMapper
import cn.flightfeather.supervision.domain.mapper.RestaurantBaseInfoMapper
import cn.flightfeather.supervision.domain.mapper.VehicleBaseInfoMapper
import cn.flightfeather.supervision.infrastructure.utils.UUIDGenerator
import cn.flightfeather.supervision.lightshare.service.UserSpecialInfoService
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
import org.springframework.stereotype.Service
 
@Service
class UserSpecialInfoServiceImpl(
    private val baseInfoMapper: BaseInfoMapper,
    private val restaurantBaseInfoMapper: RestaurantBaseInfoMapper,
    private val vehicleBaseInfoMapper: VehicleBaseInfoMapper
) : UserSpecialInfoService {
 
    override fun findOneRestaurant(id: String): BaseResponse<RestaurantBaseInfo> {
        val res = restaurantBaseInfoMapper.selectByPrimaryKey(id) ?: return BaseResponse(false, "用户id不存在")
        return BaseResponse(true, data = res)
    }
 
    override fun saveRestaurant(info: RestaurantBaseInfo): BaseResponse<Int> {
        if (info.rbGuid == null) return BaseResponse(false, "必须指定主键为用户id")
        baseInfoMapper.selectByPrimaryKey(info.rbGuid) ?: return BaseResponse(false, "创建餐饮信息之前请先创建用户基本信息")
        restaurantBaseInfoMapper.selectByPrimaryKey(info.rbGuid)?.run { return BaseResponse(false, "餐饮信息已存在,无法重复新建") }
        val res = restaurantBaseInfoMapper.insert(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "插入数据库失败", data = res)
        }
    }
 
    override fun updateRestaurant(info: RestaurantBaseInfo): BaseResponse<Int> {
        val res = restaurantBaseInfoMapper.updateByPrimaryKeySelective(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "更新数据库失败", data = res)
        }
    }
 
    override fun findOneVehicleRepair(id: String): BaseResponse<VehicleBaseInfo> {
        val res = vehicleBaseInfoMapper.selectByPrimaryKey(id) ?: return BaseResponse(false, "用户id不存在")
        return BaseResponse(true, data = res)
    }
 
    override fun saveVehicleRepair(info: VehicleBaseInfo): BaseResponse<Int> {
        if (info.vbGuid == null) return BaseResponse(false, "必须指定主键为用户id")
        baseInfoMapper.selectByPrimaryKey(info.vbGuid) ?: return BaseResponse(false, "创建汽修信息之前请先创建用户基本信息")
        vehicleBaseInfoMapper.selectByPrimaryKey(info.vbGuid)?.run { return BaseResponse(false, "汽修信息已存在,无法重复新建") }
        val res = vehicleBaseInfoMapper.insert(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "插入数据库失败", data = res)
        }
    }
 
    override fun updateVehicleRepair(info: VehicleBaseInfo): BaseResponse<Int> {
        val res = vehicleBaseInfoMapper.updateByPrimaryKeySelective(info)
        return if (res == 1) {
            BaseResponse(true, data = res)
        } else {
            BaseResponse(false, "更新数据库失败", data = res)
        }
    }
}