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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.ard.route.service.impl;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.ard.common.annotation.DataScope;
import com.ard.common.utils.DateUtils;
import com.ard.common.utils.uuid.IdUtils;
import com.ard.route.domain.route.ArdRouteGrouping;
import com.ard.route.mapper.ArdRouteGroupingMapper;
import com.ard.route.mapper.ArdRouteInforMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ard.route.service.IArdRouteGroupingService;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * 文件夹Service业务层处理
 * 
 * @author xia
 * @date 2025-10-18
 */
@Service
public class ArdRouteGroupingServiceImpl implements IArdRouteGroupingService {
 
    @Autowired
    private ArdRouteGroupingMapper ardRouteGroupingMapper;
 
    @Autowired
    private ArdRouteInforMapper ardRouteInforMapper;
 
    /**
     * 查询分组
     * 
     * @param id 分组主键
     * @return 分组
     */
    @Override
    public ArdRouteGrouping selectArdRouteGroupingById(String id) {
        ArdRouteGrouping ardRouteGrouping = ardRouteGroupingMapper.selectArdRouteGroupingById(id);
        ardRouteGrouping.setArdRouteInforLS(ardRouteInforMapper.selectArdRouteInforByGroupingId(id));
        return ardRouteGrouping;
    }
 
    /**
     * 查询分组列表
     * 
     * @param ardRouteGrouping 分组
     * @return 分组
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<ArdRouteGrouping> selectArdRouteGroupingList(ArdRouteGrouping ardRouteGrouping) {
        List<ArdRouteGrouping> list = ardRouteGroupingMapper.selectArdRouteGroupingList(ardRouteGrouping);
        for (ArdRouteGrouping routeGrouping : list) {
            routeGrouping.setArdRouteInforLS(ardRouteInforMapper.selectArdRouteInforByGroupingId(routeGrouping.getId()));
        }
        return list;
    }
 
    /**
     * 新增分组
     * 
     * @param ardRouteGrouping 分组
     * @return 结果
     */
    @Override
    public int insertArdRouteGrouping(ArdRouteGrouping ardRouteGrouping) {
        ardRouteGrouping.setId(IdUtils.simpleUUID());
        ardRouteGrouping.setCreateTime(DateUtils.getNowDate());
        // 获取当前数据条数
        int count = ardRouteGroupingMapper.selectArdRouteGroupingList(null).size();
        ardRouteGrouping.setSerialNumber(count + 1);
        return ardRouteGroupingMapper.insertArdRouteGrouping(ardRouteGrouping);
    }
 
    /**
     * 修改分组
     * 
     * @param ardRouteGrouping 分组
     * @return 结果
     */
    @Override
    public int updateArdRouteGrouping(ArdRouteGrouping ardRouteGrouping) {
        // 不能修改默认分组
        if ("0".equals(ardRouteGrouping.getId())) {
            throw new RuntimeException("不能修改默认分组");
        }
        ardRouteGrouping.setUpdateTime(DateUtils.getNowDate());
        return ardRouteGroupingMapper.updateArdRouteGrouping(ardRouteGrouping);
    }
 
    /**
     * 批量删除分组
     * 
     * @param ids 需要删除的分组主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Integer> deleteArdRouteGroupingByIds(String[] ids) {
        // 检查是否包含默认分组,不能删除默认分组
        for (String id : ids) {
            if ("0".equals(id)) {
                throw new RuntimeException("不能删除默认分组");
            }
        }
 
        Map<String, Integer> result = new HashMap<>();
        try {
            // 先删除航线信息
            int informationCount = ardRouteInforMapper.deleteRouteInforByGroupingIds(ids);
            result.put("informationCount", informationCount);
 
            // 再删除分组
            int groupingCount = ardRouteGroupingMapper.deleteArdRouteGroupingByIds(ids);
            result.put("groupingCount", groupingCount);
 
            return result;
        } catch (Exception e) {
            throw e; // 抛出异常让事务回滚
        }
    }
 
    /**
     * 删除分组信息
     * 
     * @param id 分组主键
     * @return 结果
     */
    @Override
    public int deleteArdRouteGroupingById(String id) {
        return ardRouteGroupingMapper.deleteArdRouteGroupingById(id);
    }
 
}