提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.demo.service.impl; |
X |
2 |
|
|
3 |
import cn.hutool.core.bean.BeanUtil; |
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
5 |
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
6 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
7 |
import com.dl.common.core.domain.PageQuery; |
|
8 |
import com.dl.common.core.page.TableDataInfo; |
|
9 |
import com.dl.common.utils.StringUtils; |
|
10 |
import com.dl.demo.domain.TestDemo; |
|
11 |
import com.dl.demo.domain.bo.TestDemoBo; |
|
12 |
import com.dl.demo.domain.vo.TestDemoVo; |
|
13 |
import com.dl.demo.mapper.TestDemoMapper; |
|
14 |
import com.dl.demo.service.ITestDemoService; |
|
15 |
import lombok.RequiredArgsConstructor; |
|
16 |
import org.springframework.stereotype.Service; |
|
17 |
|
|
18 |
import java.util.Collection; |
|
19 |
import java.util.List; |
|
20 |
import java.util.Map; |
|
21 |
|
|
22 |
/** |
|
23 |
* 测试单表Service业务层处理 |
|
24 |
* |
|
25 |
* @author Lion Li |
|
26 |
* @date 2021-07-26 |
|
27 |
*/ |
|
28 |
@RequiredArgsConstructor |
|
29 |
@Service |
|
30 |
public class TestDemoServiceImpl implements ITestDemoService { |
|
31 |
|
|
32 |
private final TestDemoMapper baseMapper; |
|
33 |
|
|
34 |
@Override |
|
35 |
public TestDemoVo queryById(Long id) { |
|
36 |
return baseMapper.selectVoById(id); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public TableDataInfo<TestDemoVo> queryPageList(TestDemoBo bo, PageQuery pageQuery) { |
|
41 |
LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo); |
|
42 |
Page<TestDemoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); |
|
43 |
return TableDataInfo.build(result); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* 自定义分页查询 |
|
48 |
*/ |
|
49 |
@Override |
|
50 |
public TableDataInfo<TestDemoVo> customPageList(TestDemoBo bo, PageQuery pageQuery) { |
|
51 |
LambdaQueryWrapper<TestDemo> lqw = buildQueryWrapper(bo); |
|
52 |
Page<TestDemoVo> result = baseMapper.customPageList(pageQuery.build(), lqw); |
|
53 |
return TableDataInfo.build(result); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public List<TestDemoVo> queryList(TestDemoBo bo) { |
|
58 |
return baseMapper.selectVoList(buildQueryWrapper(bo)); |
|
59 |
} |
|
60 |
|
|
61 |
private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) { |
|
62 |
Map<String, Object> params = bo.getParams(); |
|
63 |
LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery(); |
|
64 |
lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey()); |
|
65 |
lqw.eq(StringUtils.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue()); |
|
66 |
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
|
67 |
TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
|
68 |
return lqw; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public Boolean insertByBo(TestDemoBo bo) { |
|
73 |
TestDemo add = BeanUtil.toBean(bo, TestDemo.class); |
|
74 |
validEntityBeforeSave(add); |
|
75 |
boolean flag = baseMapper.insert(add) > 0; |
|
76 |
if (flag) { |
|
77 |
bo.setId(add.getId()); |
|
78 |
} |
|
79 |
return flag; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public Boolean updateByBo(TestDemoBo bo) { |
|
84 |
TestDemo update = BeanUtil.toBean(bo, TestDemo.class); |
|
85 |
validEntityBeforeSave(update); |
|
86 |
return baseMapper.updateById(update) > 0; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* 保存前的数据校验 |
|
91 |
* |
|
92 |
* @param entity 实体类数据 |
|
93 |
*/ |
|
94 |
private void validEntityBeforeSave(TestDemo entity) { |
|
95 |
//TODO 做一些数据校验,如唯一约束 |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
|
100 |
if (isValid) { |
|
101 |
//TODO 做一些业务上的校验,判断是否需要校验 |
|
102 |
} |
|
103 |
return baseMapper.deleteBatchIds(ids) > 0; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public Boolean saveBatch(List<TestDemo> list) { |
|
108 |
return baseMapper.insertBatch(list); |
|
109 |
} |
|
110 |
} |