houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.service.demo.demo01;
H 2
3 import com.iailab.framework.common.pojo.PageResult;
4 import com.iailab.framework.common.util.object.BeanUtils;
5 import com.iailab.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
6 import com.iailab.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
7 import com.iailab.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
8 import com.iailab.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper;
9 import org.springframework.stereotype.Service;
10 import org.springframework.validation.annotation.Validated;
11
12 import javax.annotation.Resource;
13
14 import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
15 import static com.iailab.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS;
16
17 /**
18  * 示例联系人 Service 实现类
19  *
20  * @author iailab
21  */
22 @Service
23 @Validated
24 public class Demo01ContactServiceImpl implements Demo01ContactService {
25
26     @Resource
27     private Demo01ContactMapper demo01ContactMapper;
28
29     @Override
30     public Long createDemo01Contact(Demo01ContactSaveReqVO createReqVO) {
31         // 插入
32         Demo01ContactDO demo01Contact = BeanUtils.toBean(createReqVO, Demo01ContactDO.class);
33         demo01ContactMapper.insert(demo01Contact);
34         // 返回
35         return demo01Contact.getId();
36     }
37
38     @Override
39     public void updateDemo01Contact(Demo01ContactSaveReqVO updateReqVO) {
40         // 校验存在
41         validateDemo01ContactExists(updateReqVO.getId());
42         // 更新
43         Demo01ContactDO updateObj = BeanUtils.toBean(updateReqVO, Demo01ContactDO.class);
44         demo01ContactMapper.updateById(updateObj);
45     }
46
47     @Override
48     public void deleteDemo01Contact(Long id) {
49         // 校验存在
50         validateDemo01ContactExists(id);
51         // 删除
52         demo01ContactMapper.deleteById(id);
53     }
54
55     private void validateDemo01ContactExists(Long id) {
56         if (demo01ContactMapper.selectById(id) == null) {
57             throw exception(DEMO01_CONTACT_NOT_EXISTS);
58         }
59     }
60
61     @Override
62     public Demo01ContactDO getDemo01Contact(Long id) {
63         return demo01ContactMapper.selectById(id);
64     }
65
66     @Override
67     public PageResult<Demo01ContactDO> getDemo01ContactPage(Demo01ContactPageReqVO pageReqVO) {
68         return demo01ContactMapper.selectPage(pageReqVO);
69     }
70
71 }