eight
2024-12-10 f77fbfc8c07881f5239ce49b0dc78faaec3628b0
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
package cn.lihu.jh.module.ecg.service.devmanage;
 
import cn.lihu.jh.module.system.api.dict.DictDataApi;
import cn.lihu.jh.module.system.api.dict.dto.DictDataRespDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import cn.lihu.jh.module.ecg.controller.admin.devmanage.vo.*;
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DevModelDO;
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.common.util.object.BeanUtils;
 
import cn.lihu.jh.module.ecg.dal.mysql.devmanage.DevModelMapper;
 
import javax.annotation.Resource;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
 
/**
 * 设备型号 Service 实现类
 *
 * @author majianbo
 */
@Service
@Validated
public class DevModelServiceImpl implements DevModelService {
 
    @Resource
    private DevModelMapper devModelMapper;
 
    @Resource
    private DictDataApi dictDataApi;
 
    @Override
    public Integer createDevModel(DevModelSaveReqVO createReqVO) {
        // 插入
        DevModelDO devModel = BeanUtils.toBean(createReqVO, DevModelDO.class);
        devModelMapper.insert(devModel);
        // 返回
        return devModel.getId();
    }
 
    @Override
    public void updateDevModel(DevModelSaveReqVO updateReqVO) {
        // 校验存在
        validateDevModelExists(updateReqVO.getId());
        // 更新
        DevModelDO updateObj = BeanUtils.toBean(updateReqVO, DevModelDO.class);
        devModelMapper.updateById(updateObj);
    }
 
    @Override
    public void deleteDevModel(Integer id) {
        // 校验存在
        validateDevModelExists(id);
        // 删除
        devModelMapper.deleteById(id);
    }
 
    private void validateDevModelExists(Integer id) {
        if (devModelMapper.selectById(id) == null) {
            throw exception(DEV_MODEL_NOT_EXISTS);
        }
    }
 
    @Override
    public DevModelDO getDevModel(Integer id) {
        return devModelMapper.selectById(id);
    }
 
    @Override
    public PageResult<DevModelDO> getDevModelPage(DevModelPageReqVO pageReqVO) {
        return devModelMapper.selectPage(pageReqVO);
    }
 
    @Override
    public List<OptionVO> getBrandOptions(String devCategory) {
        List<String> list = devModelMapper.getBrandByCategory(devCategory);
 
        List<DictDataRespDTO> dictDataRespDTOList = dictDataApi.getDictDataList("ecg_dev_brand");
        Map<String, String> map = dictDataRespDTOList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue, DictDataRespDTO::getLabel));
 
        List<OptionVO> optionVOList = new ArrayList<>();
        list.forEach(item -> {
            OptionVO optionVO = new OptionVO();
            optionVO.setLabel( map.get(item) );
            optionVO.setValue( item );
            optionVOList.add( optionVO );
        });
        return optionVOList;
    }
 
    @Override
    public List<OptionVO> getBrandModelOptions(String devCategory, String devBrand) {
        List<String> list = devModelMapper.getModelByCategoryBrand(devCategory, devBrand);
        List<OptionVO> optionVOList = new ArrayList<>();
        list.forEach(item -> {
            OptionVO optionVO = new OptionVO();
            optionVO.setLabel( item );
            optionVO.setValue( item );
            optionVOList.add( optionVO );
        });
        return optionVOList;
    }
 
}