houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
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
package com.iailab.module.data.channel.kio.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iailab.framework.common.constant.Constant;
import com.iailab.framework.common.page.PageData;
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.ConvertUtils;
import com.iailab.module.data.channel.kio.dao.ChannelKioTagDao;
import com.iailab.module.data.channel.kio.dto.ChannelKioTagDTO;
import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity;
import com.iailab.module.data.channel.kio.service.ChannelKioTagService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年06月05日
 */
@Slf4j
@Service
public class ChannelKioTagServiceImpl extends BaseServiceImpl<ChannelKioTagDao, ChannelKioTagEntity> implements ChannelKioTagService {
    @Resource
    private ChannelKioTagDao channelKioTagDao;
 
    @Value("${iems.upload-dir}")
    private String uploadDir;
 
    @Override
    public PageData<ChannelKioTagDTO> page(Map<String, Object> params) {
        IPage<ChannelKioTagEntity> page = baseDao.selectPage(
                getPage(params, Constant.CREATE_TIME, false),
                getWrapper(params)
        );
        return getPageData(page, ChannelKioTagDTO.class);
    }
 
    @Override
    public ChannelKioTagDTO get(String id) {
        ChannelKioTagEntity entity = baseDao.selectById(id);
        return ConvertUtils.sourceToTarget(entity, ChannelKioTagDTO.class);
    }
 
    @Override
    public void save(ChannelKioTagDTO dto) {
        ChannelKioTagEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioTagEntity.class);
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        insert(entity);
    }
 
    @Override
    public void update(ChannelKioTagDTO dto) {
        ChannelKioTagEntity entity = ConvertUtils.sourceToTarget(dto, ChannelKioTagEntity.class);
        entity.setUpdateTime(new Date());
        updateById(entity);
    }
 
    @Override
    public void delete(String[] ids) {
        baseDao.deleteBatchIds(Arrays.asList(ids));
    }
 
    @Override
    public List<ChannelKioTagDTO> getByDevice(String device) {
        QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(device), "device", device)
        .orderByAsc("tag_id");
        List<ChannelKioTagEntity> list = baseDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(list, ChannelKioTagDTO.class);
    }
 
    @Override
    public ChannelKioTagDTO getByTagName(String tagName) {
        QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("tag_name", tagName);
        ChannelKioTagEntity entity = baseDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(entity, ChannelKioTagDTO.class);
    }
 
    @Override
    public void deleteByDeviceName(String name) {
        baseDao.delete(new QueryWrapper<ChannelKioTagEntity>().eq("device",name));
    }
 
    private QueryWrapper<ChannelKioTagEntity> getWrapper(Map<String, Object> params){
        String tagName = (String) params.get("tagName");
        String device = (String) params.get("device");
        QueryWrapper<ChannelKioTagEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(device), "device", device);
        wrapper.like(StringUtils.isNotBlank(tagName), "tag_name", tagName);
        wrapper.orderByDesc("create_time");
        return wrapper;
    }
 
 
}