zhangback
7 天以前 b054362aaf616bfe0be0b50ae5dc2137091dbd7d
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package com.ruoyi.tms.service.impl;
 
import java.util.List;
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.SystemDataNoEnum;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
 
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISystemDataNoService;
import com.ruoyi.tms.domain.TmsQuotePlan;
import com.ruoyi.tms.domain.vo.QuoteDetailItem;
import com.ruoyi.tms.mapper.TmsQuotePlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Async;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.core.service.BaseService;
 
import com.ruoyi.tms.mapper.TmsQuoteDetailMapper;
import com.ruoyi.tms.domain.TmsQuoteDetail;
import com.ruoyi.tms.service.ITmsQuoteDetailService;
import com.ruoyi.common.core.text.Convert;
 
/**
 * 报价明细Service业务层处理
 *
 * @author ruoyi
 * @date 2025-11-12
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TmsQuoteDetailServiceImpl  extends BaseService<TmsQuoteDetailMapper, TmsQuoteDetail> implements ITmsQuoteDetailService
{
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private TmsQuoteDetailMapper tmsQuoteDetailMapper;
 
    @Resource
    private TmsQuotePlanMapper tmsQuotePlanMapper;
    @Autowired
    ISystemDataNoService systemDataNoService;
    /**
     * 查询报价明细
     *
     * @param id 报价明细ID
     * @return 报价明细
     */
    @DataSource(DataSourceType.SLAVE)
    @Override
    public TmsQuoteDetail selectTmsQuoteDetailById(Integer id)
    {
        return tmsQuoteDetailMapper.selectTmsQuoteDetailById(id);
    }
 
    /**
     * 查询报价明细 记录数
     *
     * @param tmsQuoteDetail 报价明细
     * @return 报价明细集合
     */
    @DataSource(DataSourceType.SLAVE)
    @Override
    public int selectTmsQuoteDetailCount(TmsQuoteDetail tmsQuoteDetail)
    {
        return tmsQuoteDetailMapper.selectTmsQuoteDetailCount(tmsQuoteDetail);
    }
 
    /**
     * 查询报价明细列表
     *
     * @param tmsQuoteDetail 报价明细
     * @return 报价明细
     */
    @DataSource(DataSourceType.SLAVE)
    @Override
    public List<TmsQuoteDetail> selectTmsQuoteDetailList(TmsQuoteDetail tmsQuoteDetail)
    {
        return tmsQuoteDetailMapper.selectTmsQuoteDetailList(tmsQuoteDetail);
    }
 
    /**
     * 查询报价明细列表 异步 导出
     *
     * @param tmsQuoteDetail 报价明细
     * @param exportKey 导出功能的唯一标识
     * @return 报价明细集合
     */
    @DataSource(DataSourceType.SLAVE)
    @Async
    @Override
    public void export(TmsQuoteDetail tmsQuoteDetail,String exportKey) {
 
        super.export(TmsQuoteDetail.class,exportKey,"tmsQuoteDetailData",(pageNum)->{
            PageUtils.startPage(pageNum, Constants.EXPORT_PATE_SIZE);
            return selectTmsQuoteDetailList(tmsQuoteDetail);
        });
    }
 
 
    /**
     * 新增报价明细
     *
     * @param tmsQuoteDetail 报价明细
     * @return 结果
     */
    @Override
    public int insertTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail) {
 
        Integer quotePlanId = tmsQuoteDetail.getQuotePlanId();
        if (quotePlanId == null) {
            throw new RuntimeException("请先选择报价方案不能为空");
        }
 
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(quotePlanId);
        if (tmsQuotePlan == null) {
            throw new RuntimeException("报价方案不存在");
        }
 
        // 车型报价类型
        //if (tmsQuotePlan.getPlanType() == 0) {
            List<QuoteDetailItem> quoteItems = tmsQuoteDetail.getQuoteItems();
            if (quoteItems == null || quoteItems.isEmpty()) {
                throw new RuntimeException("请填写车型报价");
            }
 
            int count = 0;
            for (QuoteDetailItem item : quoteItems) {
 
                // 拷贝主对象固定属性
                TmsQuoteDetail newDetail = BeanUtil.copyProperties(tmsQuoteDetail, TmsQuoteDetail.class);
 
                // 拷贝 item 属性
                BeanUtil.copyProperties(item ,newDetail);
 
                // 插入
                addDetail(quotePlanId, tmsQuotePlan, newDetail);
                count++;
            }
            return count;
        //}
 
        // 普通类型
        //return addDetail(quotePlanId, tmsQuotePlan, tmsQuoteDetail);
    }
 
    public int addDetail(Integer quotePlanId, TmsQuotePlan tmsQuotePlan, TmsQuoteDetail tmsQuoteDetail){
        // 1、同一报价清单,不能添加相同【路线-车型】数据
        Long l = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .eq(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
 
        );
        if (l > 0){
            throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据");
        }
        // 2、不同报价方案,不能添加相同【客户-路线-车型】数据
        Long l1 = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .ne(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getCustomerId, tmsQuotePlan.getCustomerId())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
        );
 
 
        if (l1 > 0){
            throw new RuntimeException("不同报价方案,不能添加相同【客户-路线-车型】数据");
        }
        tmsQuoteDetail.setQuotePlanCode(tmsQuotePlan.getSystemCode());
        tmsQuoteDetail.setCustomerId(tmsQuotePlan.getCustomerId());
        SystemDataNoEnum systemDataNoEnum = tmsQuotePlan.getPlanType() == 1 ? SystemDataNoEnum.YF : SystemDataNoEnum.YS;
        String noByKey = systemDataNoService.getNoByKey(systemDataNoEnum);
        tmsQuoteDetail.setSystemCode(noByKey);
        tmsQuoteDetail.setCreateBy(SecurityUtils.getUsername());
        tmsQuoteDetail.setCreateTime(DateUtils.getNowDate());
        tmsQuoteDetail.setPlanType(tmsQuotePlan.getPlanType());
        tmsQuoteDetail.setCustomerId(tmsQuotePlan.getCustomerId());
        return tmsQuoteDetailMapper.insertTmsQuoteDetail(tmsQuoteDetail);
 
    }
 
 
 
    /**
     * 新增报价明细[批量]
     *
     * @param tmsQuoteDetails 报价明细
     * @return 结果
     */
    @Override
    public int insertTmsQuoteDetailBatch(List<TmsQuoteDetail> tmsQuoteDetails)
    {
        int rows = tmsQuoteDetailMapper.insertTmsQuoteDetailBatch(tmsQuoteDetails);
        return rows;
    }
 
 
    /**
     * 修改报价明细
     *
     * @param tmsQuoteDetail 报价明细
     * @return 结果
     */
    @Override
    public int updateTmsQuoteDetail(TmsQuoteDetail tmsQuoteDetail)
    {
        Integer quotePlanId = tmsQuoteDetail.getQuotePlanId();
        if (quotePlanId == null){
            throw new RuntimeException("请先选择报价方案不能为空");
        }
        TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(quotePlanId);
        if (tmsQuotePlan == null){
            throw new RuntimeException("报价方案不存在");
        }
        // 1、同一报价清单,不能添加相同【路线-车型】数据
        Long l = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .eq(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .ne(TmsQuoteDetail::getId, tmsQuoteDetail.getId())
        );
        if (l > 0){
            throw new RuntimeException("同一报价清单,不能添加相同【路线-车型】数据");
        }
        // 2、不同报价方案,不能添加相同【客户-路线-车型】数据
        Long l1 = tmsQuoteDetailMapper.selectCount(new LambdaQueryWrapper<TmsQuoteDetail>()
                .ne(TmsQuoteDetail::getQuotePlanId, quotePlanId)
                .ne(TmsQuoteDetail::getId, tmsQuoteDetail.getId())
                .eq(TmsQuoteDetail::getCustomerId, tmsQuotePlan.getCustomerId())
                .eq(TmsQuoteDetail::getTransportRoute, tmsQuoteDetail.getTransportRoute())
                .eq(TmsQuoteDetail::getPlanType, tmsQuotePlan.getPlanType())
                .eq(TmsQuoteDetail::getVehicleType, tmsQuoteDetail.getVehicleType())
        );
 
        if (l1 > 0){
            throw new RuntimeException("不同报价方案,不能添加相同【客户-路线-车型】数据");
        }
        tmsQuoteDetail.setUpdateBy(SecurityUtils.getUsername());
        tmsQuoteDetail.setUpdateTime(DateUtils.getNowDate());
        return tmsQuoteDetailMapper.updateTmsQuoteDetail(tmsQuoteDetail);
    }
 
    /**
     * 修改报价明细[批量]
     *
     * @param tmsQuoteDetails 报价明细
     * @return 结果
     */
    @Override
    public int updateTmsQuoteDetailBatch(List<TmsQuoteDetail> tmsQuoteDetails){
        return tmsQuoteDetailMapper.updateTmsQuoteDetailBatch(tmsQuoteDetails);
    }
 
    /**
     * 删除报价明细对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTmsQuoteDetailByIds(String ids)
    {
        return deleteTmsQuoteDetailByIds(Convert.toIntArray(ids));
    }
 
    /**
     * 删除报价明细对象
     *
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTmsQuoteDetailByIds(Integer[] ids)
    {
        return tmsQuoteDetailMapper.deleteTmsQuoteDetailByIds(ids);
    }
 
    /**
     * 删除报价明细信息
     *
     * @param id 报价明细ID
     * @return 结果
     */
    @Override
    public int deleteTmsQuoteDetailById(Integer id)
    {
        return tmsQuoteDetailMapper.deleteTmsQuoteDetailById(id);
    }
}