nidapeng
2024-04-30 e459023e11f5b7be2d86662722b70605aee7992b
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
package com.doumee.service.system.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.dao.system.SystemDictDataMapper;
import com.doumee.dao.system.SystemDictMapper;
import com.doumee.dao.system.dto.QuerySystemDictDataDTO;
import com.doumee.dao.system.model.SystemDict;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.system.vo.SystemDictDataListVO;
import com.doumee.service.system.SystemDictDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 字典数据Service实现
 * @author Eva.Caesar Liu
 * @date 2023/03/21 14:49
 */
@Service
public class SystemDictDataServiceImpl implements SystemDictDataService {
 
    @Autowired
    private SystemDictDataMapper systemDictDataMapper;
 
    @Autowired
    private SystemDictMapper systemDictMapper;
    @Override
    public Integer create(SystemDictData systemDictData) {
        systemDictDataMapper.insert(systemDictData);
        return systemDictData.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        SystemDictData systemDictData = new SystemDictData();
        systemDictData.setId(id);
        systemDictData.setDeleted(Boolean.TRUE);
        this.updateById(systemDictData);
    }
 
    @Override
    @Transactional
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }
 
    @Override
    public void updateById(SystemDictData systemDictData) {
        systemDictDataMapper.updateById(systemDictData);
    }
 
    @Override
    @Transactional
    public void updateByIdInBatch(List<SystemDictData> systemDictDatas) {
        if (CollectionUtils.isEmpty(systemDictDatas)) {
            return;
        }
        for (SystemDictData systemDictData: systemDictDatas) {
            this.updateById(systemDictData);
        }
    }
 
    @Override
    public SystemDictData findById(Integer id) {
        return systemDictDataMapper.selectById(id);
    }
 
    @Override
    public SystemDictData findOne(SystemDictData systemDictData) {
        Wrapper<SystemDictData> wrapper = new QueryWrapper<>(systemDictData);
        return systemDictDataMapper.selectOne(wrapper);
    }
 
    @Override
    public List<SystemDictData> findList(SystemDictData systemDictData) {
        Wrapper<SystemDictData> wrapper = new QueryWrapper<>(systemDictData);
        return systemDictDataMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<SystemDictDataListVO> findPage(PageWrap<QuerySystemDictDataDTO> pageWrap) {
        PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
        return PageData.from(new PageInfo<>(systemDictDataMapper.selectManageList(pageWrap.getModel())));
    }
 
    @Override
    public long count(SystemDictData systemDictData) {
        Wrapper<SystemDictData> wrapper = new QueryWrapper<>(systemDictData);
        return systemDictDataMapper.selectCount(wrapper);
    }
 
    @Override
    public List<SystemDictData> findList(Integer dicId,List<String> codes) {
        QueryWrapper<SystemDictData> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Objects.nonNull(dicId),SystemDictData::getDictId,dicId)
                .in(SystemDictData::getLabel,codes);
        return systemDictDataMapper.selectList(wrapper);
    }
 
 
 
    private SystemDictData getSystemDictDataListVO(SystemDict systemDict) {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SystemDictData systemDictData = new SystemDictData();
        systemDictData.setDictId(systemDict.getId());
        systemDictData.setDisabled(true);
        systemDictData.setSort(Constants.ONE);
        systemDictData.setCreateTime(new Date());
        systemDictData.setUpdateTime(new Date());
        systemDictData.setCreateUser(loginUserInfo.getId());
        systemDictData.setUpdateUser(loginUserInfo.getId());
 
        return systemDictData;
    }
 
}