manailin
2022-09-14 9b1df600b3afbfd4b27266dcc54026db10cd8164
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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.constants.ReturnMsgConstants;
import com.panzhihua.common.enums.SanShuoEventStatusEnum;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.sanshuo.*;
import com.panzhihua.common.utlis.CopyUtil;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ComEventMapper;
import com.panzhihua.service_community.dao.ComStreetDAO;
import com.panzhihua.service_community.entity.*;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ComStreetDO;
import com.panzhihua.service_community.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * Description 三说会堂事件表业务层实现类
 * ClassName   ComEventServiceImpl
 *
 * @author manailin
 * @date 2022-09-07 11:23:51
 */
@Slf4j
@Service("comEventService")
public class ComEventServiceImpl extends ServiceImpl<ComEventMapper, ComEvent> implements IComEventService {
 
    @Resource
    private IComEventTransferRecordService comEventTransferRecordService;
 
    @Resource
    private ComSanShuoExpertService comSanShuoExpertService;
 
    @Resource
    private IComEventResourceService comEventResourceService;
 
    @Resource
    private ComActDAO comActDAO;
 
    @Resource
    private ComStreetDAO comStreetDAO;
 
    @Resource
    private ComSanShuoIndustryCenterService comSanShuoIndustryCenterService;
 
    @Override
    public R pageByComEvent(ComEvent comEvent, Page pagination) {
        IPage<ComEvent> list = baseMapper.pageByComEvent(comEvent, pagination);
        if (list.getRecords().size() < 1) {
            return R.ok(Collections.emptyList());
        }
        list.getRecords().forEach(comEvent1 -> {
            List<ComEventResource> resourceList = comEventResourceService.list(new QueryWrapper<ComEventResource>().lambda().eq(ComEventResource::getRefId, comEvent1.getId()));
            List<ComEventRequestImageVO> comEventRequestImageVO = CopyUtil.deepCopyListObject(resourceList, ComEventRequestImageVO.class);
            comEvent1.setImages(comEventRequestImageVO);
        });
        return R.ok(list);
    }
 
    @Override
    public List<ComEvent> listByComEvent(ComEvent comEvent) {
        List<ComEvent> list = baseMapper.listByComEvent(comEvent);
        if (list.size() < 1) {
            return Collections.emptyList();
        }
        return list;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R insertComEvent(ComEvent comEvent) {
        ComSanshuoExpert expert = comSanShuoExpertService.getById(comEvent.getSpecialistId());
        if (comEvent.getRequestUserCommunity() != null) {
            ComActDO community = comActDAO.selectById(comEvent.getRequestUserCommunity());
            comEvent.setCurrentOrgName(community.getName());
        }
        if (comEvent.getCenterId() != null) {
            ComSanshuoIndustryCenter center = comSanShuoIndustryCenterService.getById(comEvent.getCenterId());
            comEvent.setCurrentOrgName(center.getName());
        }
        comEvent.setUserEventStatus(2);
        comEvent.setEventProcessStatus(SanShuoEventStatusEnum.UNDO.getCode());
        comEvent.setSpecialistName(expert.getName());
        comEvent.setOrderSn(DateUtils.getDateFormatString(new Date(), "yyyyMMddHHmmss") + RandomUtils.nextLong(1, 10000));
        comEvent.setInvalid(true);
        comEvent.setId(Snowflake.getId());
        comEvent.setSubmitDate(new Date());
        comEvent.setCreateAt(new Date());
        comEvent.setCreateBy(comEvent.getRequestUserId());
        comEvent.setUpdateBy(comEvent.getRequestUserId());
        comEvent.setUpdateAt(new Date());
        boolean flag = save(comEvent);
        if (!flag) {
            return R.fail(ReturnMsgConstants.DATA_EXIST);
        }
        saveEventImageList(comEvent.getImages(), comEvent.getId());
        return R.ok(ReturnMsgConstants.SAVE_SUCCESS);
    }
 
    private Boolean saveEventImageList(List<ComEventRequestImageVO> images, Long id) {
        List<ComEventResource> comEventResourceList = new ArrayList<>();
        if (!StringUtils.isEmpty(images)) {
            List<ComEventRequestImageVO> imagesList = images;
            imagesList.forEach(comEventRequestImageVO -> {
                ComEventResource comEventResource = new ComEventResource();
                comEventResource.setId(Snowflake.getId());
                comEventResource.setRefId(id);
                comEventResource.setStatus(1);
                comEventResource.setType(1);
                comEventResource.setResourceName(comEventRequestImageVO.getName());
                comEventResource.setResourceSize(comEventRequestImageVO.getSize());
                comEventResource.setUrl(comEventRequestImageVO.getUrl());
                comEventResource.setDeleteFlag(false);
                comEventResourceList.add(comEventResource);
            });
        }
        return comEventResourceService.saveBatch(comEventResourceList);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateComEvent(ComEvent comEvent) {
        if (checkExist(comEvent.getOrderSn(), null)) {
            return R.fail(ReturnMsgConstants.DATA_EXIST);
        }
        int flag = baseMapper.updateById(comEvent);
        return flag > 0 ? R.ok(comEvent, ReturnMsgConstants.UPDATE_SUCCESS) : R.fail(ReturnMsgConstants.UPDATE_FALSE);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateEnabled(Long id, Boolean enabled) {
        ComEvent comEvent = baseMapper.selectById(id);
        if (comEvent == null) {
            return R.fail(ReturnMsgConstants.DATA_NOT_EXIST);
        }
        comEvent.setInvalid(enabled);
        Boolean flag = updateById(comEvent);
        return flag ? R.ok(comEvent, ReturnMsgConstants.UPDATE_SUCCESS) : R.fail(ReturnMsgConstants.UPDATE_FALSE);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R conciliationEvent(ComEventConciliationVO comEventConciliationVO) {
        saveEventImageList(comEventConciliationVO.getImages(), comEventConciliationVO.getId());
        ComEvent comEvent = baseMapper.selectById(comEventConciliationVO.getId());
        comEvent.setEventSucceed(comEventConciliationVO.getEventSucceed());
        comEvent.setEventResult(comEventConciliationVO.getEventResult());
        comEvent.setReportSuperior(comEventConciliationVO.getReportSuperior());
        comEvent.setCurrentEventProcessResult(comEventConciliationVO.getCurrentEventProcessResult());
        //如果当前请求,需要上报上级进行处理
        if (comEventConciliationVO.getReportSuperior()) {
            if (comEvent.getCurrentProcessType() == 2) {
                //查询街道的账号
                comEvent.setCurrentProcessType(3);
                ComActDO comActDO = comActDAO.selectById(comEvent.getCurrentOrgId());
                comEvent.setCurrentOrgId(comActDO.getStreetId().toString());
            } else {
                //查询街道的上级区域账号
                comEvent.setCurrentProcessType(4);
                try {
                    ComStreetDO street = comStreetDAO.selectById(comEvent.getCurrentOrgId());
                    comEvent.setCurrentOrgId(street.getAreaCode().toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        baseMapper.updateById(comEvent);
        return R.ok();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R cancelRequest(Long id) {
        ComEvent comEvent = baseMapper.selectById(id);
        if (comEvent.getEventProcessStatus() == SanShuoEventStatusEnum.UNDO.getCode().intValue()
                || comEvent.getEventProcessStatus() == SanShuoEventStatusEnum.VALID.getCode().intValue()) {
            comEvent.setId(id);
            comEvent.setUserEventStatus(4);
            comEvent.setEventProcessStatus(SanShuoEventStatusEnum.CANCEL.getCode());
            comEvent.setRevokeDes("用户手动取消");
            baseMapper.updateById(comEvent);
            return R.ok();
        } else {
            return R.fail("当前申请已经受理,不能取消!");
        }
    }
 
    @Override
    public HashMap detail(String id) {
        HashMap map = new HashMap(3);
        ComEventDetailVO comEventDetailVO = new ComEventDetailVO();
        ComEvent comEvent = baseMapper.selectById(id);
        ComSanshuoExpert specter = comSanShuoExpertService.getById(comEvent.getSpecialistId());
        CopyUtil.copyProperties(comEvent, comEventDetailVO);
        List<ComEventResource> resourceList = comEventResourceService.list(new QueryWrapper<ComEventResource>().lambda().eq(ComEventResource::getRefId, id));
        List<ComEventRequestImageVO> comEventRequestImageVO = CopyUtil.deepCopyListObject(resourceList, ComEventRequestImageVO.class);
        comEventDetailVO.setImages(comEventRequestImageVO);
        map.put("specter", specter);
        map.put("eventDetail", comEventDetailVO);
        List<ComEventTransferRecord> transferRecord = comEventTransferRecordService.list(new QueryWrapper<ComEventTransferRecord>().lambda().eq(ComEventTransferRecord::getEventId, id));
        map.put("transferLog", transferRecord);
        List<ComEventResource> resource = comEventResourceService.list(new QueryWrapper<ComEventResource>().lambda().eq(ComEventResource::getRefId, id)
                .eq(ComEventResource::getStatus, 5));
        map.put("archiveImage", resource);
        return map;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R acceptRequest(Long id, Long specterId) {
        ComEvent comEvent = new ComEvent();
        comEvent.setId(id);
        comEvent.setSpecialistId(specterId);
        ComSanshuoExpert specter = comSanShuoExpertService.getById(specterId);
        comEvent.setSpecialistAcceptTime(new Date());
        comEvent.setSpecialistName(specter.getName());
        comEvent.setEventProcessStatus(SanShuoEventStatusEnum.ACCEPT.getCode());
        baseMapper.updateById(comEvent);
        return R.ok();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R reappoint(Long id, Long specialistId) {
        ComEvent comEvent = new ComEvent();
        comEvent.setId(id);
        comEvent.setSpecialistId(specialistId);
        ComSanshuoExpert specter = comSanShuoExpertService.getById(specialistId);
        comEvent.setSpecialistAcceptTime(new Date());
        comEvent.setSpecialistName(specter.getName());
        comEvent.setEventProcessStatus(SanShuoEventStatusEnum.ACCEPT.getCode());
        baseMapper.updateById(comEvent);
        return R.ok();
    }
 
    @Override
    public R calculate() {
        List<ComEventCalculateVO> calculateList = baseMapper.calculate();
        return R.ok(calculateList);
    }
 
    @Override
    public R archiveRequest(ComEventArchiveVO comEventArchiveVO, LoginUserInfoVO sysUser) {
        ComEvent comEvent = baseMapper.selectById(comEventArchiveVO.getId());
        comEvent.setEventProcessStatus(6);
        comEvent.setResult(comEventArchiveVO.getResult());
        baseMapper.updateById(comEvent);
        ComEventTransferRecord comEventTransferRecord = new ComEventTransferRecord();
        comEventTransferRecord.setEventId(comEvent.getId());
        comEventTransferRecord.setSave(true);
        comEventTransferRecord.setProcessResult(comEventArchiveVO.getResult());
        comEventTransferRecord.setProcessResultData(new Date().toString());
        comEventTransferRecord.setProcessDate(new Date());
        comEventTransferRecord.setProcessBy(sysUser.getUserId());
        comEventTransferRecord.setProcessByName(sysUser.getName());
        comEventTransferRecord.setProcessType(1);
        comEventTransferRecord.setCreateAt(new Date());
        comEventTransferRecord.setSpecialistId(comEvent.getSpecialistId());
        comEventTransferRecord.setSpecialistOrg(comEvent.getCurrentOrgId());
        comEventTransferRecord.setSpecialistLevel(comEvent.getSpecialistLevel());
        comEventTransferRecord.setSpecialistName(comEvent.getSpecialistName());
        comEventTransferRecord.setEventResult(comEvent.getEventSucceed());
        comEventTransferRecord.setEventStatus(comEvent.getEventProcessStatus());
        comEventTransferRecordService.insertComEventTransferRecord(comEventTransferRecord);
        return R.ok();
    }
 
    private Boolean checkExist(String sn, Long id) {
        ComEvent comEvent = new ComEvent();
        comEvent.setOrderSn(sn);
        QueryWrapper<ComEvent> queryWrapper = new QueryWrapper<>(comEvent);
        if (id != null) {
            queryWrapper.ne("id", id);
        }
        Integer count = baseMapper.selectCount(queryWrapper);
        return count > 0;
    }
}