xuhy
2026-04-23 d4ee06a8a87ebcba64c22a45f04edca4085f28c0
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.xiaopeng.operation.service.impl;
 
import com.xiaopeng.api.model.operation.XpOpenCity;
import com.xiaopeng.api.model.operation.XpRoutePlan;
import com.xiaopeng.common.core.exception.ServiceException;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.security.utils.SecurityUtils;
import com.xiaopeng.operation.dto.RoutePlanAddDTO;
import com.xiaopeng.operation.dto.RoutePlanEditDTO;
import com.xiaopeng.operation.mapper.XpOpenCityMapper;
import com.xiaopeng.operation.mapper.XpRoutePlanMapper;
import com.xiaopeng.operation.query.RoutePlanPageListQuery;
import com.xiaopeng.operation.service.IXpRoutePlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 * 路线规划配置 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2026-02-03
 */
@Service
public class XpRoutePlanServiceImpl extends ServiceImpl<XpRoutePlanMapper, XpRoutePlan> implements IXpRoutePlanService {
 
    @Resource
    private XpOpenCityMapper openCityMapper;
 
    @Override
    public PageInfo<XpRoutePlan> pageList(RoutePlanPageListQuery query) {
        // 创建分页对象
        PageInfo<XpRoutePlan> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        // 调用Mapper查询
        List<XpRoutePlan> list = this.baseMapper.pageList(pageInfo, query);
        // 设置结果
        pageInfo.setRecords(list);
        return pageInfo;
    }
 
    @Override
    public void add(RoutePlanAddDTO dto) {
        // 1. 根据openCityId查询城市信息
        XpOpenCity openCity = openCityMapper.selectById(dto.getOpenCityId());
        if (openCity == null) {
            throw new ServiceException("开通城市不存在");
        }
 
        // 2. 创建路线规划配置对象
        XpRoutePlan routePlan = new XpRoutePlan();
        routePlan.setOpenCityId(dto.getOpenCityId());
        routePlan.setPlanName(dto.getPlanName());
        routePlan.setRemarks(dto.getRemarks());
        routePlan.setRoutePlanRule(dto.getRoutePlanRule());
 
        // 3. 填充省市区信息
        routePlan.setProvinceName(openCity.getProvinceName());
        routePlan.setProvinceCode(openCity.getProvinceCode());
        routePlan.setCityName(openCity.getCityName());
        routePlan.setCityCode(openCity.getCityCode());
        routePlan.setDistrictName(openCity.getDistrictName());
        routePlan.setDistrictCode(openCity.getDistrictCode());
        // 5. 保存到数据库
        this.save(routePlan);
    }
 
    @Override
    public void edit(RoutePlanEditDTO dto) {
        // 1. 查询原记录是否存在
        XpRoutePlan routePlan = this.getById(dto.getId());
        if (routePlan == null) {
            throw new ServiceException("路线规划配置不存在");
        }
 
        // 2. 根据openCityId查询城市信息
        XpOpenCity openCity = openCityMapper.selectById(dto.getOpenCityId());
        if (openCity == null) {
            throw new ServiceException("开通城市不存在");
        }
 
        // 3. 更新字段
        routePlan.setOpenCityId(dto.getOpenCityId());
        routePlan.setPlanName(dto.getPlanName());
        routePlan.setRemarks(dto.getRemarks());
        routePlan.setRoutePlanRule(dto.getRoutePlanRule());
 
        // 4. 更新省市区信息
        routePlan.setProvinceName(openCity.getProvinceName());
        routePlan.setProvinceCode(openCity.getProvinceCode());
        routePlan.setCityName(openCity.getCityName());
        routePlan.setCityCode(openCity.getCityCode());
        routePlan.setDistrictName(openCity.getDistrictName());
        routePlan.setDistrictCode(openCity.getDistrictCode());
//        routePlan.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getNickName());
        // 5. 保存更新
        this.updateById(routePlan);
    }
 
    @Override
    public void deleteById(Long id) {
        // 1. 检查记录是否存在
        XpRoutePlan routePlan = this.getById(id);
        if (routePlan == null) {
            throw new ServiceException("路线规划配置不存在");
        }
 
        // 2. 逻辑删除(MyBatis-Plus自动处理)
        this.removeById(id);
    }
}