mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.*;
import com.panzhihua.service_community.entity.ComActColumn;
import com.panzhihua.service_community.entity.ComActSocialOrg;
import com.panzhihua.service_community.entity.ComActSocialWorker;
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.Arrays;
import java.util.Date;
import java.util.List;
 
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
 
/**
 * 社工(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;
    @Resource
    private ComActActivityDAO comActActivityDAO;
    @Resource
    private ComActColumnDao comActColumnDao;
    /**
     * 新增社工
     * @param comActSocialWorkerAddDTO
     * @return 新增结果
     */
    @Override
    public R add(ComActSocialWorkerAddDTO comActSocialWorkerAddDTO){
        ComActSocialWorker comActSocialWorker = comActSocialWorkerMapper.selectOne(new LambdaQueryWrapper<ComActSocialWorker>()
                .eq(ComActSocialWorker::getTelephone, comActSocialWorkerAddDTO.getTelephone())
                .eq(ComActSocialWorker::getCommunityId, comActSocialWorkerAddDTO.getCommunityId()));
        if (nonNull(comActSocialWorker)) {
            return R.fail("手机号已存在");
        }
        ComActSocialWorker comActSocialWorker1 = comActSocialWorkerMapper.selectOne(new LambdaQueryWrapper<ComActSocialWorker>()
                .eq(ComActSocialWorker::getIdCard, comActSocialWorkerAddDTO.getIdCard())
                .eq(ComActSocialWorker::getCommunityId, comActSocialWorkerAddDTO.getCommunityId()));
        if (nonNull(comActSocialWorker1)) {
            return R.fail("当前身份证号码已存在社工");
        }
        ComActSocialWorker comActSocialWorkerDO = new ComActSocialWorker();
        BeanUtils.copyProperties(comActSocialWorkerAddDTO, comActSocialWorkerDO);
        comActSocialWorkerDO.setCreateBy(comActSocialWorkerAddDTO.getUserId());
        comActSocialWorkerDO.setCreateAt(new Date());
        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());
        updateWorkerSkill(comActSocialWorkerDO);
        if(comActSocialWorkerMapper.updateById(comActSocialWorkerDO)>0){
            return R.ok();
        }
        return R.fail();
    }
 
    private void updateWorkerSkill(ComActSocialWorker socialWorker) {
        String skillType = socialWorker.getSkillType();
        if (isNotBlank(skillType)) {
            List<String> skillList = Arrays.asList(skillType.split(","));
            List<String> list = new ArrayList<String>(skillList);
            list.remove(socialWorker.toString());
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {
                String skillId = list.get(i);
                ComActColumn skillColumn = comActColumnDao.selectById(skillId);
                if (i < list.size() - 1) {
                    sb.append(skillId);
                    sb.append(",");
                    sb1.append(skillColumn.getName());
                    sb1.append(",");
                } else {
                    sb.append(skillId);
                    sb1.append(skillColumn.getName());
                }
            }
            socialWorker.setSkillType(sb.toString());
            socialWorker.setSkillTypeName(sb1.toString());
        }
    }
 
    /**
     * 分页查找社工
     * @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<ComActSocialWorkerVO> comActSocialWorkerDetails(Long id){
        ComActSocialWorkerVO comActSocialWorkerDO = comActSocialWorkerMapper.selectOneById(id);
        return R.ok(comActSocialWorkerDO);
    }
 
    @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.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);
                    }
                }
                if(StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getCredential())){
                    if("是".equals(comActSocialWorkerExcelVO.getCredential())){
                        comActSocialWorkerDO.setCredential(1);
                    }
                    else {
                        comActSocialWorkerDO.setCredential(0);
                    }
                }
                if(StringUtils.isNotEmpty(comActSocialWorkerExcelVO.getCredential())){
                    if("是".equals(comActSocialWorkerExcelVO.getCredential())){
                        comActSocialWorkerDO.setCredential(1);
                    }
                    else {
                        comActSocialWorkerDO.setCredential(0);
                    }
                }
                list.add(comActSocialWorkerDO);
            }
            this.saveBatch(list);
        }
 
        return R.ok();
    }
 
    @Override
    public R activity(CommonPage commonPage) {
        return R.ok(comActSocialWorkerMapper.selectActivity(new Page(commonPage.getPage(),commonPage.getSize()),commonPage.getParamId()));
    }
 
    @Override
    public R activityList(CommonPage commonPage) {
        return R.ok(comActActivityDAO.selectActivityBySocialWorker(new Page(commonPage.getPage(),commonPage.getSize()),commonPage));
    }
}