baoshiwei
2025-03-12 3c2c87364b89de46d12e95abd5bdf8cbd2c6dbf6
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
package cn.shlanbao.qms.service.impl;
 
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import cn.shlanbao.qms.domain.bo.LbDeviceBo;
import cn.shlanbao.qms.domain.vo.LbDeviceVo;
import cn.shlanbao.qms.domain.LbDevice;
import cn.shlanbao.qms.mapper.LbDeviceMapper;
import cn.shlanbao.qms.service.ILbDeviceService;
 
import java.util.List;
import java.util.Map;
import java.util.Collection;
 
/**
 * 测试仪Service业务层处理
 *
 * @author bsw
 * @date 2024-12-12
 */
@RequiredArgsConstructor
@Service
public class LbDeviceServiceImpl implements ILbDeviceService {
 
    private final LbDeviceMapper baseMapper;
 
    /**
     * 查询测试仪
     *
     * @param id 主键
     * @return 测试仪
     */
    @Override
    public LbDeviceVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }
 
    /**
     * 分页查询测试仪列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 测试仪分页列表
     */
    @Override
    public TableDataInfo<LbDeviceVo> queryPageList(LbDeviceBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<LbDevice> lqw = buildQueryWrapper(bo);
        Page<LbDeviceVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }
 
    /**
     * 查询符合条件的测试仪列表
     *
     * @param bo 查询条件
     * @return 测试仪列表
     */
    @Override
    public List<LbDeviceVo> queryList(LbDeviceBo bo) {
        LambdaQueryWrapper<LbDevice> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }
 
    private LambdaQueryWrapper<LbDevice> buildQueryWrapper(LbDeviceBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<LbDevice> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceType()), LbDevice::getDeviceType, bo.getDeviceType());
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceCode()), LbDevice::getDeviceCode, bo.getDeviceCode());
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceGroup()), LbDevice::getDeviceGroup, bo.getDeviceGroup());
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceDept()), LbDevice::getDeviceDept, bo.getDeviceDept());
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceStation()), LbDevice::getDeviceStation, bo.getDeviceStation());
        return lqw;
    }
 
    /**
     * 新增测试仪
     *
     * @param bo 测试仪
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(LbDeviceBo bo) {
        LbDevice add = MapstructUtils.convert(bo, LbDevice.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }
 
    /**
     * 修改测试仪
     *
     * @param bo 测试仪
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(LbDeviceBo bo) {
        LbDevice update = MapstructUtils.convert(bo, LbDevice.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }
 
    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(LbDevice entity){
        //TODO 做一些数据校验,如唯一约束
    }
 
    /**
     * 校验并批量删除测试仪信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }
}