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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
package com.dg.core.service.impl;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dg.core.db.gen.entity.*;
import com.dg.core.db.gen.mapper.*;
import com.dg.core.db.manual.pojo.QueryResults;
import com.dg.core.db.manual.pojo.RecommendResult;
import com.dg.core.db.manual.pojo.Search;
import com.dg.core.service.ITransactionEventService;
 
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class TransactionEventImpl extends ServiceImpl<TransactionEventMapper, TransactionEvent> implements ITransactionEventService {
 
    @Resource
    private OrganizationChartMapper organizationChartMapper;
 
    @Resource
    private KeywordMapper keywordMapper;
 
    @Resource
    private AutomessageTransactionEventInterviewMapper automessageTransactionEventInterviewMapper;
 
 
    @Resource
    private GuideRepairOrderMapper guideRepairOrderMapper;
 
 
    @Resource
    private  AutomessagePolicyDocumentsMapper automessagePolicyDocumentsMapper;
 
    @Override
    public TransactionEvent selectConfigData(String Id, SysUser sysUser) {
        TransactionEvent transactionEvent = baseMapper.selectConfigData(Id);
        //如果当前没有登录用户则不增加浏览次数
        if (sysUser != null) {
            LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
            LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
            AutomessageTransactionEventInterview automessageTransactionEventInterview = automessageTransactionEventInterviewMapper.selectOne(new QueryWrapper<AutomessageTransactionEventInterview>()
                    .lambda().eq(AutomessageTransactionEventInterview::getTransactionEventId, Id)
                    .eq(AutomessageTransactionEventInterview::getUserId, sysUser.getUserId())
                    .orderByDesc(AutomessageTransactionEventInterview::getInterviewTime)
                    .last("limit 1"));
            transactionEvent.setQueryTime(LocalDateTime.now());
            //判断上次访问时间是不是今天 如果是今天不增加浏览次数
            if (automessageTransactionEventInterview == null || (!(transactionEvent.getQueryTime().isAfter(startTime) && transactionEvent.getQueryTime().isBefore(endTime)))) {
                transactionEvent.setBrowseNum(transactionEvent.getBrowseNum() + 1);
                baseMapper.updateById(transactionEvent);
                AutomessageTransactionEventInterview automessageTransactionEventInterviewNew =
                        new AutomessageTransactionEventInterview();
                automessageTransactionEventInterviewNew.setTransactionEventId(Integer.valueOf(Id));
                automessageTransactionEventInterviewNew.setUserId(new Long(sysUser.getUserId()));
                automessageTransactionEventInterviewNew.setInterviewTime(LocalDateTime.now());
                automessageTransactionEventInterviewMapper.insert(automessageTransactionEventInterviewNew);
            }
        }
        return transactionEvent;
    }
 
    @Override
    public List<TransactionEvent> selectConfigList(IPage<TransactionEvent> page, Integer state,
                                                   String keyword, String classifyGrade, List<String> ids) {
        return baseMapper.selectConfigList(page, state, keyword, classifyGrade, ids);
    }
 
    @Override
    public List<TransactionEvent> selectConfigList(String keyword, String classifyGrade, List<String> ids) {
        return baseMapper.selectConfigList(keyword, classifyGrade, ids);
    }
 
    @Override
    public int insertConfig(TransactionEvent entity) {
        return baseMapper.insertConfig(entity);
    }
 
    @Override
    public int updateConfig(TransactionEvent entity) {
        return baseMapper.updateConfig(entity);
    }
 
    @Override
    public int deleteConfigById(String Id) {
        List<GuideRepairOrder> guideRepairOrders = guideRepairOrderMapper
                .selectList(new QueryWrapper<GuideRepairOrder>().lambda().eq(GuideRepairOrder::getMatterId, Id));
        if (guideRepairOrders.size() == 0) {
            return baseMapper.deleteConfigById(Id);
        }
        return 0;
    }
 
    @Override
    public int countNum(String matterAndUser, String classifyGrade, List<String> ids) {
        return baseMapper.countNum(matterAndUser, classifyGrade, ids);
    }
 
    @Override
    public QueryResults queryMatterNameList(IPage<Search> page, Integer state, Integer recommendSize, String keyWord) {
        QueryResults queryResults = new QueryResults();
        List<Search> searches = baseMapper.selectSearch(page, state, keyWord);
        queryResults.setSearchList(searches);
        List<Search> searchesAssociate = baseMapper.selectSearchAssociate(page, recommendSize, keyWord);
        queryResults.setTransactionEventList(searchesAssociate);
        queryResults.setKeywordEntityList(keywordMapper.selectByName(keyWord));
        queryResults.setTotal((baseMapper.selectSearch(keyWord).size()) + (baseMapper.selectSearchAssociate(keyWord).size()));
        List<TransactionEvent> transactionEventEntities = baseMapper.queryMatterNameList(keyWord, null);
        List<String> list = new ArrayList<>();
        for (TransactionEvent transactionEvent : transactionEventEntities) {
            if (transactionEvent.getAssociateNames() != null) {
                String[] associateNames = transactionEvent.getAssociateNames().split(",");
                for (String associateName : associateNames) {
                    list.add(associateName);
                }
            }
        }
        List<KeywordEntity> keywordEntityList = new ArrayList<>();
 
        String[] keywords = list.stream().distinct().collect(Collectors.joining(",")).split(",");//去重
        for (String keyword : keywords) {
            if (keyword != null && !keyword.equals("")) {
                KeywordEntity keywordEntity = new KeywordEntity();
                keywordEntity.setName(keyword);
                keywordEntityList.add(keywordEntity);
            }
        }
        queryResults.setKeywordAssociationList(keywordEntityList);
        return queryResults;
    }
 
    @Override
    public QueryResults queryMatterNameList(String keyWord) {
        QueryResults queryResults = new QueryResults();
        List<Search> searches = baseMapper.selectSearchList(keyWord);
        for (Search search : searches) {
            search.setTransactionEventList(baseMapper.queryMatterNameList(keyWord, search.getClassifyId().toString()));
        }
        queryResults.setOrganizationChartEntityList(organizationChartMapper.selectByKeyWord(keyWord));
        queryResults.setSearchList(searches);
        List<Search> searchesAssociate = baseMapper.selectSearchAssociateDistinct(keyWord);
        for (Search search : searchesAssociate) {
            search.setTransactionEventList(baseMapper.queryAssociateNamesList(keyWord, search.getClassifyId().toString()));
        }
        queryResults.setTransactionEventList(searchesAssociate);
        queryResults.setKeywordEntityList(keywordMapper.selectByName(keyWord));
        queryResults.setAutomessagePolicyDocuments(automessagePolicyDocumentsMapper.selectConfigList(keyWord,"2",null,null));
        queryResults.setRegulations(automessagePolicyDocumentsMapper.selectConfigList(keyWord,"1",null,null));
        return queryResults;
    }
 
 
    @Override
    public RecommendResult smartConsulting(String keyWord) {
        RecommendResult recommendResult = new RecommendResult();
        List<KeywordEntity> keywordEntityList = new ArrayList<>();
        List<TransactionEvent> transactionEventEntities = baseMapper.queryMatterNameList(keyWord, null);
        List<TransactionEvent> transactionEvents = baseMapper.queryAssociateNamesList(keyWord, null);
        recommendResult.setTransactionEventList(transactionEventEntities);
        List<String> list = new ArrayList<>();
        for (TransactionEvent transactionEvent : transactionEvents) {
//            直接返回办事指南名称
            list.add(transactionEvent.getMatterName());
//            遍历关键词列表 可能后面流程更改会遇到暂时保存代码;
      /*      if (transactionEvent.getAssociateNames() != null) {
                String[] associateNames = transactionEvent.getAssociateNames().split(",");
                for (String associateName : associateNames) {
                    list.add(associateName);
                }
            }*/
        }
        String[] keywords = list.stream().distinct().collect(Collectors.joining(",")).split(",");//去重
        for (String keyword : keywords) {
            if (keyword != null && !keyword.equals("")) {
                KeywordEntity keywordEntity = new KeywordEntity();
                keywordEntity.setName(keyword);
                keywordEntityList.add(keywordEntity);
            }
        }
        recommendResult.setKeywordEntityList(keywordEntityList);
        List<OrganizationChartEntity> organizationChartEntities = organizationChartMapper.selectByKeyWord(keyWord);
        recommendResult.setAutomessagePolicyDocuments(automessagePolicyDocumentsMapper.selectConfigList(keyWord,"2",null,null));
        recommendResult.setRegulations(automessagePolicyDocumentsMapper.selectConfigList(keyWord,"1",null,null));
        recommendResult.setOrganizationChartEntityList(organizationChartEntities);
        return recommendResult;
    }
 
    @Override
    public String selectDataIfExist(String departmentId, String matterName) {
        return baseMapper.selectDataIfExist(departmentId, matterName);
    }
 
    @Override
    public List<String> selectclassifyId(String classifyId) {
        return baseMapper.selectclassifyId(classifyId);
    }
 
    @Override
    public List<TransactionEvent> selectClassifyList(List<String> ids) {
        return baseMapper.selectClassifyList(ids);
    }
 
 
    @Override
    public int countNumByMatterName(String matterName) {
        return baseMapper.countNumByMatterName(matterName);
    }
 
    @Override
    public List<TransactionEvent> queryByClassifyIdList(String classifyId, Integer departmentId) {
        return baseMapper.queryByClassifyIdList(classifyId, departmentId);
    }
 
    @Override
    public List<TransactionEvent> queryByClassifyIdList(IPage<TransactionEvent> page, Integer state, String classifyId, Integer departmentId) {
        return baseMapper.queryByClassifyIdList(page, state, classifyId, departmentId);
    }
 
    @Override
    public List<TransactionEvent> queryByQueryTime() {
        List<TransactionEvent> transactionEvents = baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda().orderByDesc(TransactionEvent::getQueryTime));
        return transactionEvents;
    }
 
    @Override
    public List<TransactionEvent> queryByBrowseNum() {
        List<TransactionEvent> transactionEvents = baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda().orderByDesc(TransactionEvent::getBrowseNum));
        return transactionEvents;
    }
 
    @Override
    public TransactionEvent sumTransactionNum() {
        return baseMapper.sumTransactionNum();
    }
 
    @Override
    public int countNumByClassifyIdList(String classifyId, Integer departmentId) {
        return baseMapper.countNumByClassifyIdList(classifyId, departmentId);
    }
 
    @Override
    public List<TransactionEvent> selectList(String keyWord) {
        if (keyWord != null && keyWord != "") {
            return baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda().like(TransactionEvent::getMatterName, keyWord));
        } else {
            return baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda());
        }
    }
 
 
    @Override
    public Integer batchImport(String fileName, MultipartFile file) {
        boolean notNull = false;
        if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
            throw new RuntimeException("选择文件格式不正确,请下载模板上传");
        }
        boolean isExcel2003 = true;
        if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
            isExcel2003 = false;
        }
        InputStream is = null;
        try {
            is = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Workbook wb = null;
 
        if (isExcel2003) {
            try {
                wb = new HSSFWorkbook(is);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            try {
                wb = new XSSFWorkbook(is);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        Integer failNum = 0;//失败数量
        // 获取excel的sheet页数
        int numberOfSheets = wb.getNumberOfSheets();
        for (int j = 0; j < numberOfSheets; j++) {
            int i = 2;
            //获取excel字段名称进行比较
            Sheet sheetAt = wb.getSheetAt(j);
            if(sheetAt.getRow(2)!=null){
            if (new DataFormatter().formatCellValue(sheetAt.getRow(1).getCell(1)).length()>=3){
                i--;
            }
            Row row1 = sheetAt.getRow(i);
            TransactionEvent transactionEvent = baseMapper.selectOne(new QueryWrapper<TransactionEvent>().lambda().eq(TransactionEvent::getMatterName, new DataFormatter().formatCellValue(row1.getCell(1))));
            boolean isAdd = false;
            if (transactionEvent == null) {
                transactionEvent = new TransactionEvent();
                isAdd = true;
            }
            transactionEvent.setMatterName(new DataFormatter().formatCellValue(row1.getCell(1)));
            Row row2 = sheetAt.getRow(i+1);
            transactionEvent.setSetGist("<p>" + new DataFormatter().formatCellValue(row2.getCell(1)) + "</p>");
            Row row3 = sheetAt.getRow(i+2);
            Row row4 = sheetAt.getRow(i+3);
            transactionEvent.setBasicInformation("<p> 事项名称:" + new DataFormatter().formatCellValue(row1.getCell(1)) + "<br />"
                    + new DataFormatter().formatCellValue(row3.getCell(0)) + ":" + new DataFormatter().formatCellValue(row3.getCell(1))+ "<br />"
                    + new DataFormatter().formatCellValue(row3.getCell(3)) + ":" + new DataFormatter().formatCellValue(row3.getCell(4)) + "<br />"
                    + new DataFormatter().formatCellValue(row4.getCell(0)) + ":" + new DataFormatter().formatCellValue(row4.getCell(1)) + "</p>");
             i = i+5;
            String applicationMaterial = "<p>";
            while (true) {
                Row row = sheetAt.getRow(i);
                if (new DataFormatter().formatCellValue(row.getCell(0)).equals("办理途径、条件和注意事项")) {
                    i = i + 2;
                    break;
                }
                applicationMaterial = applicationMaterial + "办理区域:" + new DataFormatter().formatCellValue(row.getCell(0)) + "<br />"
                        + "部门名称:" + new DataFormatter().formatCellValue(row.getCell(1)) + "<br />"
                        + "咨询电话:" + new DataFormatter().formatCellValue(row.getCell(2)) + "<br />"
                        + "办公地址:" + new DataFormatter().formatCellValue(row.getCell(3)) + "<br />"
                        + "办公时间:" + new DataFormatter().formatCellValue(row.getCell(4)) + "<br />";
                applicationMaterial = applicationMaterial + "<br />";
                i++;
            }
            applicationMaterial = applicationMaterial + "</p>";
            transactionEvent.setApplicationMaterial(applicationMaterial);
            String acceptConditions = "<p>";
            while (true) {
                Row row = sheetAt.getRow(i);
                if (new DataFormatter().formatCellValue(row.getCell(0)).equals("(二)网上申报")) {
                    i = i + 1;
                    break;
                }
                acceptConditions = acceptConditions + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        +new DataFormatter().formatCellValue( row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; "
                         +new DataFormatter().formatCellValue( row.getCell(3)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(4)) + "&nbsp; ";
                acceptConditions = acceptConditions + "<br />";
                i++;
            }
            acceptConditions = acceptConditions + "</p>";
            transactionEvent.setAcceptConditions(acceptConditions);
            String rates = "<p>";
            while (true) {
                Row row = sheetAt.getRow(i);
                if (new DataFormatter().formatCellValue(row.getCell(0)).equals("(三)手机移动申报")) {
                    i = i + 1;
                    break;
                }
                rates = rates + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; "
                        +new DataFormatter().formatCellValue( row.getCell(3)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(4)) + "&nbsp; ";
                rates = rates + "<br />";
                i++;
            }
            rates = rates + "</p>";
            transactionEvent.setRates(rates);
            String transactionArea = "<p>";
            while (true) {
                Row row = sheetAt.getRow(i);
                if (new DataFormatter().formatCellValue(row.getCell(0)).equals("(四)经营许可(备案)事项程序运行图谱(附电子版)")) {
                    i = i + 1;
                    break;
                }
                transactionArea = transactionArea + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; "
                        +new DataFormatter().formatCellValue( row.getCell(3)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(4)) + "&nbsp; ";
                transactionArea = transactionArea + "<br />";
                i++;
            }
            transactionArea = transactionArea + "</p>";
            transactionEvent.setTransactionArea(transactionArea);
            String handlingProcedures = "<p>";
            while (true) {
                Row row = sheetAt.getRow(i);
                if (new DataFormatter().formatCellValue(row.getCell(0)).equals("(五)经营许可(备案)事项实施内容一览表(附电子版)")) {
                    i = i + 1;
                    break;
                }
                handlingProcedures = handlingProcedures + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; "
                        +new DataFormatter().formatCellValue( row.getCell(3)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(4)) + "&nbsp; ";
                handlingProcedures = handlingProcedures + "<br />";
                i++;
            }
            handlingProcedures = handlingProcedures + "</p>";
            transactionEvent.setHandlingProcedures(handlingProcedures);
            int ans;
            if (isAdd) {
                ans = baseMapper.insert(transactionEvent);
            } else {
                ans = baseMapper.updateById(transactionEvent);
            }
            if (ans <= 0) {
                failNum++;
            }
            }
 
        }
        if (failNum == 0) {//
            return 3;//全部导入成功
        } else if (failNum < numberOfSheets) {
            return 2;//部分导入成功
        } else if (failNum.equals(numberOfSheets)) {
            return 0;//导入失败
        }
        return 0;
    }
 
 
}