goupan
2024-04-03 5506e9a45e717ffcb67ec313b5a4e8206d9b3a39
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
package cn.stylefeng.roses.kernel.expand.modular.modular.service.impl;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpandField;
import cn.stylefeng.roses.kernel.expand.modular.modular.enums.SysExpandFieldExceptionEnum;
import cn.stylefeng.roses.kernel.expand.modular.modular.mapper.SysExpandFieldMapper;
import cn.stylefeng.roses.kernel.expand.modular.modular.pojo.request.SysExpandFieldRequest;
import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandFieldService;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * 业务拓展-字段信息业务实现层
 *
 * @author fengshuonan
 * @date 2022/03/29 23:47
 */
@Service
public class SysExpandFieldServiceImpl extends ServiceImpl<SysExpandFieldMapper, SysExpandField> implements SysExpandFieldService {
 
    @Override
    public void add(SysExpandFieldRequest sysExpandFieldRequest) {
        SysExpandField sysExpandField = new SysExpandField();
        BeanUtil.copyProperties(sysExpandFieldRequest, sysExpandField);
        this.save(sysExpandField);
    }
 
    @Override
    public void del(SysExpandFieldRequest sysExpandFieldRequest) {
        SysExpandField sysExpandField = this.querySysExpandField(sysExpandFieldRequest);
        this.removeById(sysExpandField.getFieldId());
    }
 
    @Override
    public void edit(SysExpandFieldRequest sysExpandFieldRequest) {
        SysExpandField sysExpandField = this.querySysExpandField(sysExpandFieldRequest);
        BeanUtil.copyProperties(sysExpandFieldRequest, sysExpandField);
        this.updateById(sysExpandField);
    }
 
    @Override
    public SysExpandField detail(SysExpandFieldRequest sysExpandFieldRequest) {
        return this.querySysExpandField(sysExpandFieldRequest);
    }
 
    @Override
    public PageResult<SysExpandField> findPage(SysExpandFieldRequest sysExpandFieldRequest) {
        LambdaQueryWrapper<SysExpandField> wrapper = createWrapper(sysExpandFieldRequest);
        Page<SysExpandField> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
        return PageResultFactory.createPageResult(sysRolePage);
    }
 
    @Override
    public List<SysExpandField> findList(SysExpandFieldRequest sysExpandFieldRequest) {
        LambdaQueryWrapper<SysExpandField> wrapper = this.createWrapper(sysExpandFieldRequest);
        return this.list(wrapper);
    }
 
    /**
     * 获取信息
     *
     * @author fengshuonan
     * @date 2022/03/29 23:47
     */
    private SysExpandField querySysExpandField(SysExpandFieldRequest sysExpandFieldRequest) {
        SysExpandField sysExpandField = this.getById(sysExpandFieldRequest.getFieldId());
        if (ObjectUtil.isEmpty(sysExpandField)) {
            throw new ServiceException(SysExpandFieldExceptionEnum.SYS_EXPAND_FIELD_NOT_EXISTED);
        }
        return sysExpandField;
    }
 
    /**
     * 创建查询wrapper
     *
     * @author fengshuonan
     * @date 2022/03/29 23:47
     */
    private LambdaQueryWrapper<SysExpandField> createWrapper(SysExpandFieldRequest sysExpandFieldRequest) {
        LambdaQueryWrapper<SysExpandField> queryWrapper = new LambdaQueryWrapper<>();
 
        Long expandId = sysExpandFieldRequest.getExpandId();
 
        queryWrapper.eq(ObjectUtil.isNotNull(expandId), SysExpandField::getExpandId, expandId);
 
        return queryWrapper;
    }
 
}