FormServiceImpl.java
2.85 KB
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
package vion.service.impl;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.dto.FormDTO;
import vion.mapper.FormMapper;
import vion.model.Account;
import vion.model.Form;
import vion.model.Store;
import vion.service.IFormService;
import vion.vo.FormVO;
/**
* @author HlQ
* @date 2023/12/12
*/
@Service
@RequiredArgsConstructor
public class FormServiceImpl extends MPJBaseServiceImpl<FormMapper, Form> implements IFormService {
private final Converter converter;
@Override
public Page<FormVO> list(FormDTO dto) {
MPJLambdaWrapper<Form> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Form.class))
.selectAll(Form.class)
.selectAs(Account::getName, FormVO::getAccountName)
.selectAs(Store::getName, FormVO::getStoreName)
.leftJoin(Account.class, Account::getId, Form::getAccountId)
.leftJoin(Store.class, Store::getId, Form::getStoreId);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), FormVO.class, wrapper);
}
@Override
public Object save(FormDTO dto) {
Form form = converter.convert(dto, Form.class);
String nanoId = IdUtil.nanoId();
form.setUuid(nanoId);
return this.save(form) ? JSONUtil.ofObj().set("id", form.getId()).set("uuid", nanoId) : "创建失败";
}
@Override
public String updateById(Long id, FormDTO dto) {
Form form = converter.convert(dto, Form.class);
form.setId(id);
return this.updateById(form) ? "更新成功" : "更新失败";
}
@Override
public FormVO getByUniqueId(Long id, String uuid) {
MPJLambdaWrapper<Form> wrapper = new MPJLambdaWrapper<Form>()
.selectAll(Form.class)
.selectAs(Account::getName, FormVO::getAccountName)
.selectAs(Store::getName, FormVO::getStoreName)
.leftJoin(Account.class, Account::getId, Form::getAccountId)
.leftJoin(Store.class, Store::getId, Form::getStoreId)
.eq(ObjUtil.isNotNull(id), Form::getId, id)
.eq(StrUtil.isNotBlank(uuid), Form::getUuid, uuid);
return this.selectJoinOne(FormVO.class, wrapper);
}
@Override
public String updByUuid(String uuid, FormDTO dto) {
Form form = converter.convert(dto, Form.class);
return this.lambdaUpdate().eq(Form::getUuid, uuid).update(form) ? "提交成功" : "提交失败";
}
}