huanghongfa
2021-07-31 802bbc9b1a26334607b04ab562e62594e383d2c2
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
221
222
223
224
225
226
227
228
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.enums.SafeWordStatusEnum;
import com.panzhihua.common.model.dtos.community.ComSwDangerReportHandleDTO;
import com.panzhihua.common.model.dtos.community.ComSwDangerReportRectifyDTO;
import com.panzhihua.common.model.dtos.community.ComSwPatrolRecordPageDTO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngCarExcelVO;
import com.panzhihua.common.model.vos.community.ComSwDangerReportExcelVO;
import com.panzhihua.common.model.vos.community.ComSwDangerReportVO;
import com.panzhihua.common.model.vos.community.ComSwSafetyWorkRecordVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComSwDangerReportDAO;
import com.panzhihua.service_community.dao.ComSwPatrolRecordDAO;
import com.panzhihua.service_community.dao.ComSwPatrolRecordReportDAO;
import com.panzhihua.service_community.model.dos.ComSwDangerReportDO;
import com.panzhihua.service_community.model.dos.ComSwPatrolRecordDO;
import com.panzhihua.service_community.model.dos.ComSwPatrolRecordReportDO;
import com.panzhihua.service_community.model.dos.ComSwSafetyWorkRecordDO;
import com.panzhihua.service_community.service.ComSwDangerReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
/**
 * @auther txb
 * @create 2021-07-27 14:31:04
 * @describe 服务实现类
 */
@Slf4j
@Service
public class ComSwDangerReportServiceImpl extends ServiceImpl<ComSwDangerReportDAO, ComSwDangerReportDO> implements ComSwDangerReportService {
 
    @Resource
    private ComSwDangerReportDAO comSwDangerReportDAO;
 
    @Resource
    private ComSwPatrolRecordDAO comSwPatrolRecordDAO;
 
    @Resource
    private ComSwPatrolRecordReportDAO comSwPatrolRecordReportDAO;
 
    @Resource
    private UserService userService;
 
    @Override
    public R pageDangerReport(ComSwPatrolRecordPageDTO comSwPatrolRecordPageDTO) {
        Page page = new Page<>();
        Long pageNum = comSwPatrolRecordPageDTO.getPageNum();
        Long pageSize = comSwPatrolRecordPageDTO.getPageSize();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1L;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10L;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
 
        IPage<ComSwDangerReportVO> iPage = comSwDangerReportDAO.pageDangerReport(page, comSwPatrolRecordPageDTO);
        if (!iPage.getRecords().isEmpty()) {
            iPage.getRecords().forEach(comSwDangerReportVO -> {
                if (StringUtils.isNotEmpty(comSwDangerReportVO.getAssignPerson())) {
                    comSwDangerReportVO.setIsAssign(ComSwDangerReportVO.isOk.no);
                }else {
                    comSwDangerReportVO.setIsAssign(ComSwDangerReportVO.isOk.yes);
                }
            });
        }
        return R.ok(iPage);
    }
 
    @Override
    public R detailDangerReport(Long dangerReportId) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(dangerReportId);
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        ComSwDangerReportVO comSwDangerReportVO = new ComSwDangerReportVO();
        ComSwPatrolRecordReportDO comSwPatrolRecordReportDO = comSwPatrolRecordReportDAO.selectOne(new QueryWrapper<ComSwPatrolRecordReportDO>().lambda().eq(ComSwPatrolRecordReportDO::getReportId, dangerReportId));
        if (null != comSwPatrolRecordReportDO) {
            ComSwPatrolRecordDO comSwPatrolRecordDO = comSwPatrolRecordDAO.selectById(comSwPatrolRecordReportDO.getPatrolRecordId());
            BeanUtils.copyProperties(comSwPatrolRecordDO, comSwDangerReportVO);
        }
        BeanUtils.copyProperties(comSwDangerReportDO, comSwDangerReportVO);
 
        //组装巡查类型
        if(StringUtils.isNotEmpty(comSwDangerReportVO.getPatrolType())){
            StringBuilder sb = new StringBuilder();
            String patrolTypes[] = comSwDangerReportVO.getPatrolType().split(",");
            for (int i = 0; i < patrolTypes.length; i++) {
                if(i != 0){
                    sb.append(",");
                }
                if(patrolTypes[i].equals("1")){
                    sb.append("防火巡查");
                }else if(patrolTypes[i].equals("2")){
                    sb.append("防汛巡查");
                }else if(patrolTypes[i].equals("3")){
                    sb.append("防疫巡查");
                }
            }
            comSwDangerReportVO.setPatrolType(sb.toString());
        }
 
        //查询人员信息
        if(StringUtils.isNotEmpty(comSwDangerReportVO.getRectifyPerson())){
            StringBuilder sb = new StringBuilder();
            String personIds[] = comSwDangerReportVO.getRectifyPerson().split(",");
            for (int i = 0; i < personIds.length; i++) {
                if(i != 0){
                    sb.append(",");
                }
                Map<String,String> personMap = comSwPatrolRecordDAO.getPbServiceTeamById(personIds[i]);
                if(personMap != null){
                    sb.append(personMap.get("name"));
                }
            }
            comSwDangerReportVO.setPersonName(sb.toString());
        }
 
        //查询填报人名称
        if(comSwDangerReportVO.getCreateBy() != null){
            comSwDangerReportVO.setCreateName(comSwPatrolRecordDAO.getCreateName(comSwDangerReportVO.getCreateBy()));
        }
 
        //查询指派人名称
        if(StringUtils.isNotEmpty(comSwDangerReportVO.getAssignPerson())){
            StringBuilder sb = new StringBuilder();
            String personIds[] = comSwDangerReportVO.getAssignPerson().split(",");
            for (int i = 0; i < personIds.length; i++) {
                if(i != 0){
                    sb.append(",");
                }
                Map<String,String> personMap = comSwPatrolRecordDAO.getPbServiceTeamById(personIds[i]);
                if(personMap != null){
                    sb.append(personMap.get("name"));
                }
            }
            comSwDangerReportVO.setAssignPersonName(sb.toString());
        }
 
        //查询巡查人员
        Map<String,String> map = comSwPatrolRecordDAO.getPatrolPersonName(comSwDangerReportVO.getId());
        if(map != null){
            comSwDangerReportVO.setPatrolName(map.get("person_name"));
        }
 
        return R.ok(comSwDangerReportVO);
    }
 
    @Override
    public R detailDangerReportByPrId(Long patrolRecordId) {
        ComSwPatrolRecordDO comSwPatrolRecordDO = comSwPatrolRecordDAO.selectById(patrolRecordId);
        if(comSwPatrolRecordDO == null){
            return R.fail("该隐患报告不存在");
        }
        ComSwDangerReportVO comSwDangerReportVO = new ComSwDangerReportVO();
        ComSwPatrolRecordReportDO comSwPatrolRecordReportDO = comSwPatrolRecordReportDAO.selectOne(new QueryWrapper<ComSwPatrolRecordReportDO>().lambda().eq(ComSwPatrolRecordReportDO::getPatrolRecordId, patrolRecordId));
        if (null != comSwPatrolRecordReportDO) {
            ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwPatrolRecordReportDO.getReportId());
            if (null == comSwDangerReportDO) {
                return R.fail("该隐患报告不存在");
            }
            BeanUtils.copyProperties(comSwDangerReportDO, comSwDangerReportVO);
        }
        BeanUtils.copyProperties(comSwPatrolRecordDO, comSwDangerReportVO);
        return R.ok(comSwDangerReportVO);
    }
 
    @Override
    public R handleDangerReport(ComSwDangerReportHandleDTO comSwDangerReportHandleDTO) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwDangerReportHandleDTO.getDangerReportId());
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        BeanUtils.copyProperties(comSwDangerReportHandleDTO, comSwDangerReportDO);
        comSwDangerReportDO.setStatus(String.valueOf(SafeWordStatusEnum.YCL.getCode()));
        int update = comSwDangerReportDAO.updateById(comSwDangerReportDO);
        if (update > 0) {
            return R.ok();
        }
        return R.fail("处理失败");
    }
 
    @Override
    public R rectifyDangerReport(ComSwDangerReportRectifyDTO comSwDangerReportRectifyDTO) {
        ComSwDangerReportDO comSwDangerReportDO = comSwDangerReportDAO.selectById(comSwDangerReportRectifyDTO.getDangerReportId());
        if (null == comSwDangerReportDO) {
            return R.fail("该隐患报告不存在");
        }
        BeanUtils.copyProperties(comSwDangerReportRectifyDTO, comSwDangerReportDO);
        comSwDangerReportDO.setStatus(String.valueOf(SafeWordStatusEnum.YZG.getCode()));
        int update = comSwDangerReportDAO.updateById(comSwDangerReportDO);
        if (update > 0) {
            return R.ok();
        }
        return R.fail("整改失败");
    }
 
    @Override
    public R exportDangerReport(List<Long> dangerReportIds) {
        List<ComSwDangerReportExcelVO> list = comSwDangerReportDAO.exportDangerReport(dangerReportIds);
        list.forEach(comSwDangerReportExcelVO -> {
            List<String> patrolUserIds = Arrays.asList(comSwDangerReportExcelVO.getPatrolPerson().split(","));
            List<String> patrolPhones = new ArrayList<>();
            for (String userId : patrolUserIds) {
                LoginUserInfoVO loginUserInfoVO = userService.getUserInfoByUserId(userId).getData();
                patrolPhones.add(loginUserInfoVO.getPhone());
            }
            comSwDangerReportExcelVO.setPatrolPersonPhone(StringUtils.join(patrolPhones,","));
        });
        return R.ok(list);
    }
}