101captain
2021-10-26 d111b0f70d5930935fc8658e389a1b7b1947f74a
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.civil.*;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.civil.ComActSocialWorkerDetailsVO;
import com.panzhihua.common.model.vos.civil.ComActSocialWorkerVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ComActSocialOrgDao;
import com.panzhihua.service_community.dao.ComStreetDAO;
import com.panzhihua.service_community.entity.ComActSocialOrg;
import com.panzhihua.service_community.entity.ComActSocialWorker;
import com.panzhihua.service_community.dao.ComActSocialWorkerDao;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ComStreetDO;
import com.panzhihua.service_community.service.ComActSocialWorkerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 社工(ComActSocialWorker)表服务实现类
 *
 * @author makejava
 * @since 2021-10-25 10:56:48
 */
@Slf4j
@Service
public class ComActSocialWorkerServiceImpl extends ServiceImpl<ComActSocialWorkerDao, ComActSocialWorker> implements ComActSocialWorkerService {
    @Resource
    private ComActSocialWorkerDao comActSocialWorkerMapper;
    @Resource
    private ComStreetDAO comStreetDAO;
    @Resource
    private ComActSocialOrgDao comActSocialOrgMapper;
    @Resource
    private ComActDAO comActDAO;
    /**
     * 新增社工
     * @param comActSocialWorkerAddDTO
     * @return 新增结果
     */
    @Override
    public R add(ComActSocialWorkerAddDTO comActSocialWorkerAddDTO){
        ComActSocialWorker comActSocialWorkerDO = new ComActSocialWorker();
        BeanUtils.copyProperties(comActSocialWorkerAddDTO, comActSocialWorkerDO);
        comActSocialWorkerDO.setCreateBy(comActSocialWorkerAddDTO.getUserId());
        if(comActSocialWorkerMapper.insert(comActSocialWorkerDO)>0){
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 修改社工
     * @param comActSocialWorkerEditDTO
     * @return 维护结果
     */
    @Override
    public R edit(ComActSocialWorkerEditDTO comActSocialWorkerEditDTO){
        ComActSocialWorker comActSocialWorkerDO = new ComActSocialWorker();
        BeanUtils.copyProperties(comActSocialWorkerEditDTO, comActSocialWorkerDO);
        //comActSocialWorkerDO.setUpdateAt(new Date());
        if(comActSocialWorkerMapper.updateById(comActSocialWorkerDO)>0){
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 分页查找社工
     * @param pageComActSocialWorkerDTO
     * @return 维护结果
     */
    @Override
    public R<IPage<ComActSocialWorkerVO>> query(PageComActSocialWorkerDTO pageComActSocialWorkerDTO){
        Page page = new Page(1,10);
        if(pageComActSocialWorkerDTO.getPageNum()!=null) {
            page.setCurrent(pageComActSocialWorkerDTO.getPageNum());
        }
        if(pageComActSocialWorkerDTO.getPageSize()!=null) {
            page.setSize(pageComActSocialWorkerDTO.getPageSize());
        }
        return R.ok(comActSocialWorkerMapper.findByPage(page, pageComActSocialWorkerDTO));
    }
 
    /**
     * 删除社工
     * @param ComActSocialWorkerDeleteDTO
     * @return 平台用户信息
     */
    @Override
    public R delete(ComActSocialWorkerDeleteDTO ComActSocialWorkerDeleteDTO){
        return R.ok(this.comActSocialWorkerMapper.deleteById(ComActSocialWorkerDeleteDTO.getId()));
    }
 
    /**
     * 查询社工详细信息
     * @param id 社工 id
     * @return 查找结果
     */
    @Override
    public R<ComActSocialWorkerDetailsVO> comActSocialWorkerDetails(Long id){
        ComActSocialWorker comActSocialWorkerDO = comActSocialWorkerMapper.selectById(id);
        if(comActSocialWorkerDO!=null) {
            ComActSocialWorkerDetailsVO comActSocialWorkerDetailsVO = new ComActSocialWorkerDetailsVO();
            BeanUtils.copyProperties(comActSocialWorkerDO, comActSocialWorkerDetailsVO);
            return R.ok(comActSocialWorkerDetailsVO);
        }
        return R.fail();
    }
 
    @Override
    public R export(List<ComActSocialWorkerExcelVO> lis, Long communityId) {
        if(!CollectionUtils.isEmpty(lis)){
            List<ComActSocialWorker> list=new ArrayList<>();
            for(ComActSocialWorkerExcelVO comActSocialWorkerExcelVO:lis) {
                ComActSocialWorker comActSocialWorkerDO = new ComActSocialWorker();
                BeanUtils.copyProperties(comActSocialWorkerExcelVO,comActSocialWorkerDO);
                if (StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getStreetId())) {
                    ComStreetDO comStreetDO=comStreetDAO.selectOne(new QueryWrapper<ComStreetDO>().eq("name",comActSocialWorkerExcelVO.getStreetId()));
                    if(comStreetDO!=null){
                        comActSocialWorkerDO.setStreetId(comStreetDO.getStreetId());
                    }
                }
                if (StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getSocialOrgId())) {
                    ComActSocialOrg comActSocialOrgDO=comActSocialOrgMapper.selectOne(new QueryWrapper<ComActSocialOrg>().eq("name",comActSocialWorkerExcelVO.getSocialOrgId()));
                    if(comActSocialOrgDO!=null){
                        comActSocialWorkerDO.setSocialOrgId(comActSocialOrgDO.getId());
                    }
                }
                if(StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getCommunityId())){
                    ComActDO comActDO= comActDAO.selectOne(new QueryWrapper<ComActDO>().eq("name",comActSocialWorkerExcelVO.getCommunityId()));
                    if(comActDO!=null){
                        comActSocialWorkerDO.setCommunityId(comActDO.getCommunityId());
                    }
                }
                if(StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getGen())){
                    if("男".equals(comActSocialWorkerExcelVO.getGen())){
                        comActSocialWorkerDO.setGen(1);
                    }
                    else {
                        comActSocialWorkerDO.setGen(0);
                    }
                }
                list.add(comActSocialWorkerDO);
            }
            this.saveBatch(list);
        }
 
        return R.ok();
    }
}