liding
2 天以前 c0efb2e8358f4e7ee0774c340afd453c3d0c2471
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
package com.ruoyi.basic.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.CoalPlanDto;
import com.ruoyi.basic.entity.CoalField;
import com.ruoyi.basic.entity.CoalPlan;
import com.ruoyi.basic.mapper.CoalFieldMapper;
import com.ruoyi.basic.mapper.CoalPlanMapper;
import com.ruoyi.basic.service.CoalPlanService;
import com.ruoyi.basic.vo.CoalFieldVo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 煤质信息表,记录煤炭质量检测相关数据 服务实现类
 * </p>
 *
 * @author ruoyi
 * @since 2025-06-09
 */
@Service
@RequiredArgsConstructor
public class CoalPlanServiceImpl extends ServiceImpl<CoalPlanMapper, CoalPlan> implements CoalPlanService {
 
    private final CoalPlanMapper coalPlanMapper;
 
    private final CoalFieldMapper coalFieldMapper;
 
    @Override
    public IPage<CoalPlan> selectCoalFieldList(Page page, CoalPlanDto coalPlanDto) {
        LambdaQueryWrapper<CoalPlan> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(coalPlanDto.getSearchAll())){
            queryWrapper.like(CoalPlan::getPlan,coalPlanDto.getSearchAll());
        }
        return coalPlanMapper.selectPage(page, queryWrapper);
    }
 
    @Override
    public int addOrEditCoalPlan(CoalPlanDto coalPlanDto) {
        CoalPlan coalPlan = new CoalPlan();
        BeanUtils.copyProperties(coalPlanDto, coalPlan);
        if (Objects.isNull(coalPlanDto.getId())) {
            return coalPlanMapper.insert(coalPlan);
        } else {
            return coalPlanMapper.updateById(coalPlan);
        }
    }
 
    @Override
    public int delCoalPlanByIds(Long[] ids) {
        // 检查参数
        if (ids == null || ids.length == 0) {
            return 0;
        }
        // 构造更新条件
        UpdateWrapper<CoalPlan> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids)
                .set("deleted", 1);  // 设置 deleted 为 1 表示已删除
        // 执行批量逻辑删除
        return coalPlanMapper.update(null, updateWrapper);
    }
 
    @Override
    public List<CoalPlan> selectAllList() {
        return coalPlanMapper.selectList(null);
    }
 
    @Override
    public List<CoalFieldVo> selectCoalPlanById(Long id) {
        CoalPlan coalPlan = coalPlanMapper.selectById(id);
        LambdaQueryWrapper<CoalField> coalFieldLambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<Long> ids = Arrays.stream(coalPlan.getFieldIds().split(",")).map(String::trim).map(Long::parseLong).collect(Collectors.toList());
        coalFieldLambdaQueryWrapper.in(CoalField::getId, ids);
        List<CoalField> coalFields = coalFieldMapper.selectList(coalFieldLambdaQueryWrapper);
        return coalFields.stream()
                .map(coalField -> {
                    CoalFieldVo dto = new CoalFieldVo();
                    dto.setId(coalField.getId());
                    dto.setFields(coalField.getFields());
                    dto.setFieldName(coalField.getFieldName());
                    return dto;
                })
                .collect(Collectors.toList());
    }
}