101captain
2022-07-20 c40f8e3d2e08e108780091776437242528bf61d6
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
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.enterprise.AddEnterpriseDTO;
import com.panzhihua.common.model.dtos.community.enterprise.EditEnterpriseDTO;
import com.panzhihua.common.model.dtos.community.enterprise.PageEnterpriseDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ComActEnterpriseDAO;
import com.panzhihua.service_community.entity.ComActEnterprise;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.service.ComActEnterpriseService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
import static java.util.Objects.isNull;
 
/**
 * (ComActEnterprise)表服务实现类
 *
 * @author makejava
 * @since 2022-05-31 10:17:02
 */
@Service("comActEnterpriseService")
public class ComActEnterpriseServiceImpl extends ServiceImpl<ComActEnterpriseDAO, ComActEnterprise>
    implements ComActEnterpriseService {
 
    @Resource
    private ComActDAO comActDAO;
 
    /**
     * 新增社区企业
     * @param addEnterpriseDTO
     * @return
     */
    @Override
    public R addEnterprise(AddEnterpriseDTO addEnterpriseDTO) {
        ComActDO comActDO = comActDAO.selectById(addEnterpriseDTO.getCommunityId());
        ComActEnterprise enterprise = new ComActEnterprise();
        BeanUtils.copyProperties(addEnterpriseDTO, enterprise);
        enterprise.setStreetId(comActDO.getStreetId());
        int result = this.baseMapper.insert(enterprise);
        if (result > 0) {
            return R.ok();
        }
        return R.fail("操作失败,请重新尝试");
    }
 
    /**
     * 修改社区企业
     * @param editEnterpriseDTO
     * @return
     */
    @Override
    public R editEnterprise(EditEnterpriseDTO editEnterpriseDTO) {
        ComActEnterprise enterprise = this.baseMapper.selectById(editEnterpriseDTO.getId());
        if (isNull(enterprise)) {
            return R.fail("资源不存在");
        }
        ComActDO comActDO = comActDAO.selectById(editEnterpriseDTO.getCommunityId());
        BeanUtils.copyProperties(editEnterpriseDTO, enterprise);
        enterprise.setStreetId(comActDO.getStreetId());
        int result = this.baseMapper.updateById(enterprise);
        if (result > 0) {
            return R.ok();
        }
        return R.fail("操作失败,请重新尝试");
    }
 
    /**
     * 删除社区企业
     * @param id
     * @return
     */
    @Override
    public R deleteEnterprise(Long id) {
        this.baseMapper.deleteById(id);
        return R.ok();
    }
 
    /**
     * 获取社区企业详情
     * @param id
     * @return
     */
    @Override
    public R detailEnterprise(Long id) {
        return R.ok(this.baseMapper.detailEnterprise(id));
    }
 
    /**
     * 分页查询社区企业
     * @param pageEnterpriseDTO
     * @return
     */
    @Override
    public R pageEnterprise(PageEnterpriseDTO pageEnterpriseDTO) {
        Page page = new Page<>();
        page.setSize(pageEnterpriseDTO.getPageSize());
        page.setCurrent(pageEnterpriseDTO.getPageNum());
        return R.ok(this.baseMapper.pageEnterprise(page, pageEnterpriseDTO));
    }
}