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());
|
routePlan.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
// 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);
|
}
|
}
|