广州市综治平台后端
xusd
2025-06-16 96fdf159f9128cfa3ecfd5cd32313302373e35e5
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
package cn.huge.module.ctuser.service;
 
import cn.huge.base.common.constant.GzRegionBaseEnum;
import cn.huge.base.common.dto.SelectTermDTO;
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.IdUtils;
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.base.common.utils.SelectTermUtils;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.constant.BaseConsts;
import cn.huge.module.ctuser.dao.mapper.CtUnitMapper;
import cn.huge.module.ctuser.domain.po.*;
import cn.huge.module.ctuser.dto.CtUnitWeChatCountDTO;
import cn.huge.module.cust.constant.RoleBaseEnum;
import cn.huge.module.cust.constant.UserBaseConsts;
import cn.huge.module.cust.dto.CtUnitDTO;
import cn.huge.module.cust.dto.CtUserDTO;
import cn.huge.module.kind.domain.po.SyRegion;
import cn.huge.module.kind.service.SyRegionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author liyj
 * @version 1.0.0
 * @title: Excel表格操作业务逻辑处理
 * @Description Excel表格操作业务逻辑处理
 * @company hugeinfo
 * @Time 2024-08-19 20:04:19
 */
@Slf4j
@Service
public class ExcelOperCtunitService {
 
    @Autowired
    private UtilsClientImpl utilsClient;
    @Autowired
    private CtUnitService ctUnitService;
    @Autowired
    private CtDeptService ctDeptService;
    @Autowired
    private CtUserService ctUserService;
    @Autowired
    private CtAccountService ctAccountService;
    @Autowired
    private CtUseroleService ctUseroleService;
    @Autowired
    private SyRegionService syRegionService;
 
    /**
     * 获取单元格数据
     *
     * @param sheet 表示Excel工作表对象,从中获取指定单元格的数据
     * @param r 表示单元格所在的行索引,从0开始计数
     * @param c 表示单元格所在的列索引,从0开始计数
     * @return 返回指定单元格中的数据,如果单元格为空或者工作表为空则返回null
     */
    public String transform(Sheet sheet, int r, int c) {
        // 检查工作表是否为空
        if (ObjectUtils.isNotEmpty(sheet)) {
            // 获取指定行和列的单元格
            Cell cell = sheet.getRow(r).getCell(c);
            // 检查单元格是否为空
            if (ObjectUtils.isNotEmpty(cell)) {
                // 注意:setCellType方法已弃用,可考虑使用其他替代方法
                cell.setCellType(CellType.STRING);
                // 获取单元格中的字符串值
                String val = cell.getStringCellValue();
                // 去除字符串中的空格并返回
                return val.replace(" ", "");
            } else {
                // 单元格为空,返回null
                return null;
            }
        } else {
            // 工作表为空,返回null
            return null;
        }
    }
 
    /**
     * 通过Excel创建单位和账号
     *
     * @param request
     */
    public void inputByExcel241124(MultipartHttpServletRequest request) {
        try {
            Iterator<String> itr = request.getFileNames();
            while (itr.hasNext()) {
                MultipartFile file = request.getFile(itr.next());
                String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                if (".xls".equals(fileSuffix) || ".xlsx".equals(fileSuffix) || "xls".equals(fileSuffix) || "xlsx".equals(fileSuffix)) {
                    InputStream inputStream = file.getInputStream();
                    Workbook wb = null;
                    //当excel是2003时
                    if (".xls".equals(fileSuffix)) {
                        wb = new HSSFWorkbook(inputStream);
                    } else {
                        wb = new XSSFWorkbook(inputStream);
                    }
                    //得到第一个shell
                    Sheet sheet = wb.getSheetAt(0);
                    //得到Excel的行数
                    int totalRows = sheet.getPhysicalNumberOfRows();
                    //人员信息
                    Date nowDate = DateUtils.getNowDate();
                    for (int r = 1; r < totalRows; r++) {
                        try {
                            // 获取数据
                            String area = this.transform(sheet, r, 0);
                            String areaName = this.transform(sheet, r, 1);
                            String road = this.transform(sheet, r, 2);
                            String roadName = this.transform(sheet, r, 3);
                            String village = this.transform(sheet, r, 4);
                            String villageName = this.transform(sheet, r, 5);
                            String id = this.transform(sheet, r, 6);
                            String unitName = this.transform(sheet, r, 7);
                            String parentId = this.transform(sheet, r, 8);
                            String level = this.transform(sheet, r, 9);
                            String unitGrade = this.transform(sheet, r, 10);
                            String unitType = this.transform(sheet, r, 11);
                            String trueName = this.transform(sheet, r, 12);
                            String mobile = this.transform(sheet, r, 13);
                            String idcard = this.transform(sheet, r, 14);
                            String cipher = this.transform(sheet, r, 15);
                            if (StringUtils.isBlank(cipher)) {
                                // 默认密码
                                cipher = UserBaseConsts.MR_CIPHER_GZ;
                            }
                            // 新增单位
                            CtUnit ctUnit = new CtUnit();
                            ctUnit.setId(id);
                            ctUnit.setLevel(Integer.parseInt(level));
                            ctUnit.setParentId(parentId);
                            ctUnit.setUnitGrade(Integer.parseInt(unitGrade));
                            ctUnit.setUnitFun(UserBaseConsts.UNIT_FUN_1);
                            ctUnit.setUnitType(Integer.parseInt(unitType));
                            ctUnit.setCourtStatus(UserBaseConsts.COURT_STATUS_0);
                            ctUnit.setUnitName(unitName);
                            if (UserBaseConsts.UNIT_GRADE_2 == ctUnit.getUnitGrade()) {
                                ctUnit.setUnitDes(unitName);
                            } else {
                                ctUnit.setUnitDes(roadName + "-" + unitName);
                            }
                            ctUnit.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                            ctUnit.setProv(GzRegionBaseEnum.PROV_1.getIndex());
                            ctUnit.setProvName(GzRegionBaseEnum.PROV_1.getDes());
                            ctUnit.setCity(GzRegionBaseEnum.CITY_1.getIndex());
                            ctUnit.setCityName(GzRegionBaseEnum.CITY_1.getDes());
                            ctUnit.setArea(area);
                            ctUnit.setAreaName(areaName);
                            ctUnit.setRoad(road);
                            ctUnit.setRoadName(roadName);
                            ctUnit.setVillage(village);
                            ctUnit.setVillageName(villageName);
                            ctUnit.setAddr(ctUnit.getUnitDes());
                            ctUnit.setFindStatus(UserBaseConsts.FIND_STATUS_0);
                            ctUnit.setDispStatus(UserBaseConsts.DISP_STATUS_0);
                            ctUnit.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                            ctUnit.setCreateTime(nowDate);
                            ctUnit.setUpdateTime(nowDate);
                            try {
                                ctUnitService.save(ctUnit);
                            } catch (Exception e) {
                                log.error("已存在");
                            }
                            // 新增人员
                            CtUser ctUser = new CtUser();
                            ctUser.setId(utilsClient.getNewTimeId());
                            ctUser.setTrueName(trueName);
                            ctUser.setAcc(mobile);
                            if (StringUtils.isNotBlank(idcard)) {
                                ctUser.setMobile(mobile);
                            }
                            ctUser.setIdcard(idcard);
                            ctUser.setUnitId(ctUnit.getId());
                            ctUser.setUnitName(ctUnit.getUnitName());
                            ctUser.setCreateTime(nowDate);
                            ctUser.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                            ctUser.setRealStatus(UserBaseConsts.REAL_STATUS_0);
                            ctUser.setStatus(UserBaseConsts.USER_STATUS_1);
                            ctUser.setFindStatus(UserBaseConsts.FIND_STATUS_0);
                            ctUser.setDispStatus(UserBaseConsts.DISP_STATUS_0);
                            ctUser.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                            ctUser.setCustId("-1");
                            ctUser.setCreateTime(nowDate);
                            ctUser.setUpdateTime(nowDate);
                            ctUserService.save(ctUser);
                            // 新增人员账号
                            CtAccount ctAccount = new CtAccount();
                            ctAccount.setId(utilsClient.getNewTimeId());
                            ctAccount.setCustId(ctUser.getCustId());
                            ctAccount.setUserId(ctUser.getId());
                            ctAccount.setAccType(UserBaseConsts.ACC_TYPE_1);
                            ctAccount.setAcc(ctUser.getAcc());
                            ctAccount.setCipher(DigestUtils.md5DigestAsHex(cipher.getBytes()));
                            ctAccount.setCipherOpen(cipher);
                            ctAccount.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                            ctAccount.setCustId("-1");
                            ctAccount.setCreateTime(nowDate);
                            ctAccount.setCipherTime(nowDate);
                            ctAccount.setUpdateTime(nowDate);
                            ctAccountService.save(ctAccount);
                            // 新增人员角色关系-单位管理员
                            CtUserole ctUserole1 = new CtUserole();
                            ctUserole1.setId(utilsClient.getNewTimeId());
                            ctUserole1.setUserId(ctUser.getId());
                            ctUserole1.setRoleId(RoleBaseEnum.ROLE_3.getIndex());
                            ctUserole1.setRoleCode(RoleBaseEnum.ROLE_3.getIndex());
                            ctUserole1.setRoleName(RoleBaseEnum.ROLE_3.getDes());
                            ctUserole1.setCustId("-1");
                            ctUserole1.setCreateTime(nowDate);
                            ctUserole1.setUpdateTime(nowDate);
                            ctUseroleService.save(ctUserole1);
                            // 新增人员角色关系-纠纷化解人员
                            CtUserole ctUserole2 = new CtUserole();
                            ctUserole2.setId(utilsClient.getNewTimeId());
                            ctUserole2.setUserId(ctUser.getId());
                            ctUserole2.setRoleId(RoleBaseEnum.ROLE_4.getIndex());
                            ctUserole2.setRoleCode(RoleBaseEnum.ROLE_4.getIndex());
                            ctUserole2.setRoleName(RoleBaseEnum.ROLE_4.getDes());
                            ctUserole2.setCustId("-1");
                            ctUserole2.setCreateTime(nowDate);
                            ctUserole2.setUpdateTime(nowDate);
                            ctUseroleService.save(ctUserole2);
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                            continue;
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("[ExcelOperCtunitService.inputByExcel241124]调用失败,异常信息:" + e, e);
            throw new ServiceException("ExcelOperCtunitService.inputByExcel241124", e);
        }
    }
 
    /**
     * 通过Excel创建单位和账号
     *
     * @param request
     */
    public void inputByExcel250304(MultipartHttpServletRequest request) {
        String errorInfo = "";
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String custId = sdf.format(new Date());
            Iterator<String> itr = request.getFileNames();
            while (itr.hasNext()) {
                MultipartFile file = request.getFile(itr.next());
                String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
                if (".xls".equals(fileSuffix) || ".xlsx".equals(fileSuffix) || "xls".equals(fileSuffix) || "xlsx".equals(fileSuffix)) {
                    InputStream inputStream = file.getInputStream();
                    Workbook wb = null;
                    //当excel是2003时
                    if (".xls".equals(fileSuffix)) {
                        wb = new HSSFWorkbook(inputStream);
                    } else {
                        wb = new XSSFWorkbook(inputStream);
                    }
                    //得到第一个shell
                    Sheet sheet = wb.getSheetAt(0);
                    //得到Excel的行数
                    int totalRows = sheet.getPhysicalNumberOfRows();
                    //人员信息
                    Date nowDate = DateUtils.getNowDate();
                    // 调解组织所属区名称
                    String areaName = this.transform(sheet, 0, 0);
                    // 调解组织所属区
                    String area = GzRegionBaseEnum.getIndex(areaName);
                    for (int r = 2; r < totalRows; r++) {
                        try {
                            // 调解组织所属街道名称
                            String roadName = this.transform(sheet, r, 0);
                            // 调解组织名称
                            String unitName = this.transform(sheet, r, 1);
                            // 调解组织类型
                            String unitGradeStr = this.transform(sheet, r, 2);
                            int unitGrade = Integer.parseInt(unitGradeStr);
                            // 调解组织类型
                            String unitTypeStr = this.transform(sheet, r, 3);
                            int unitType = Integer.parseInt(unitTypeStr);
                            // 人员姓名
                            String trueName = this.transform(sheet, r, 4);
                            // 人员联系方式
                            String mobile = this.transform(sheet, r, 5);
                            // 人员身份证号
                            String idcard = this.transform(sheet, r, 6);
                            // 调解组织地址
                            String addr = this.transform(sheet, r, 7);
                            // 默认密码
                            String cipher = "Gzs@2025";
                            if (GzRegionBaseEnum.AREA_1.getIndex().equals(area)) {
                                cipher = "Gzth@2025";
                            } else if(GzRegionBaseEnum.AREA_2.getIndex().equals(area)) {
                                cipher = "Gzhz@2025";
                            }else if(GzRegionBaseEnum.AREA_3.getIndex().equals(area)) {
                                cipher = "Gzlw@2025";
                            }else if(GzRegionBaseEnum.AREA_4.getIndex().equals(area)) {
                                cipher = "Gzyx@2025";
                            }else if(GzRegionBaseEnum.AREA_5.getIndex().equals(area)) {
                                cipher = "Gzpy@2025";
                            }else if(GzRegionBaseEnum.AREA_6.getIndex().equals(area)) {
                                cipher = "Gzhd@2025";
                            }else if(GzRegionBaseEnum.AREA_7.getIndex().equals(area)) {
                                cipher = "Gzby@2025";
                            }else if(GzRegionBaseEnum.AREA_8.getIndex().equals(area)) {
                                cipher = "Gzns@2025";
                            }else if(GzRegionBaseEnum.AREA_9.getIndex().equals(area)) {
                                cipher = "Gzhp@2025";
                            }else if(GzRegionBaseEnum.AREA_10.getIndex().equals(area)) {
                                cipher = "Gzzc@2025";
                            }else if(GzRegionBaseEnum.AREA_11.getIndex().equals(area)) {
                                cipher = "Gzch@2025";
                            }
 
                            QueryWrapper<SyRegion> syRegionQueryWrapper = new QueryWrapper<>();
                            syRegionQueryWrapper.eq("parent_id", area).like("name", roadName);
                            SyRegion roadSyRegion = syRegionService.getOne(syRegionQueryWrapper);
                            // 查询是否存在该单位
                            QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>();
                            ctUnitQueryWrapper.eq("area", area)
                                    .eq("unit_grade", unitGrade)
                                    .eq("unit_type", unitType)
                                    .eq("unit_name", unitName);
                            if (UserBaseConsts.UNIT_GRADE_3 == unitGrade || UserBaseConsts.UNIT_GRADE_4 == unitGrade) {
                                ctUnitQueryWrapper.eq("road", roadSyRegion.getId());
                            }
                            List<CtUnit> ctUnitList = ctUnitService.list(ctUnitQueryWrapper);
                            CtUnit ctUnit = null;
                            if (CollectionUtils.isEmpty(ctUnitList)) {
                                // 新增单位
                                ctUnit = new CtUnit();
                                // 主键
                                ctUnit.setId(utilsClient.getNewTimeId());
                                // 层级
                                ctUnit.setLevel(unitGrade);
                                // 父级组织 todo
                                if (UserBaseConsts.UNIT_GRADE_2 == unitGrade) {
                                    if (UserBaseConsts.UNIT_TYPE_101 == unitType){
                                        // 综治中心,父级是广州市综治中心
                                        ctUnitQueryWrapper.clear();
                                        ctUnitQueryWrapper.eq("city", GzRegionBaseEnum.CITY_1.getIndex())
                                                .eq("unit_type", UserBaseConsts.UNIT_TYPE_101)
                                                .eq("unit_grade", UserBaseConsts.UNIT_GRADE_1);
                                        List<CtUnit> zzzxList = ctUnitService.list(ctUnitQueryWrapper);
                                        ctUnit.setParentId(zzzxList.get(0).getId());
                                    }else {
                                        // 其他,父级是区综治中心
                                        ctUnitQueryWrapper.clear();
                                        ctUnitQueryWrapper.eq("area", area)
                                                .eq("unit_type", UserBaseConsts.UNIT_TYPE_101)
                                                .eq("unit_grade", UserBaseConsts.UNIT_GRADE_2);
                                        List<CtUnit> zzzxList = ctUnitService.list(ctUnitQueryWrapper);
                                        ctUnit.setParentId(zzzxList.get(0).getId());
                                    }
                                }else if (UserBaseConsts.UNIT_GRADE_3 == unitGrade) {
                                    if (UserBaseConsts.UNIT_TYPE_101 == unitType){
                                        // 综治中心,父级是区综治中心
                                        ctUnitQueryWrapper.clear();
                                        ctUnitQueryWrapper.eq("area", area)
                                                .eq("unit_type", UserBaseConsts.UNIT_TYPE_101)
                                                .eq("unit_grade", UserBaseConsts.UNIT_GRADE_2);
                                        List<CtUnit> zzzxList = ctUnitService.list(ctUnitQueryWrapper);
                                        ctUnit.setParentId(zzzxList.get(0).getId());
                                    }else {
                                        // 其他,父级是街道综治中心
                                        ctUnitQueryWrapper.clear();
                                        ctUnitQueryWrapper.eq("area", area)
                                                .eq("unit_type", UserBaseConsts.UNIT_TYPE_101)
                                                .eq("unit_grade", UserBaseConsts.UNIT_GRADE_3)
                                                .eq("road", roadSyRegion.getId());
                                        List<CtUnit> zzzxList = ctUnitService.list(ctUnitQueryWrapper);
                                        ctUnit.setParentId(zzzxList.get(0).getId());
                                    }
                                }else if (UserBaseConsts.UNIT_GRADE_4 == unitGrade){
                                    ctUnitQueryWrapper.clear();
                                    ctUnitQueryWrapper.eq("area", area)
                                            .eq("unit_type", UserBaseConsts.UNIT_TYPE_101)
                                            .eq("unit_grade", UserBaseConsts.UNIT_GRADE_3)
                                            .eq("road", roadSyRegion.getId());
                                    List<CtUnit> zzzxList = ctUnitService.list(ctUnitQueryWrapper);
                                    ctUnit.setParentId(zzzxList.get(0).getId());
 
                                }
                                // 组织级别
                                ctUnit.setUnitGrade(unitGrade);
                                // 组织职能
                                ctUnit.setUnitFun(UserBaseConsts.UNIT_FUN_1);
                                // 组织职能
                                ctUnit.setUnitType(unitType);
                                // 是否是法院
                                if (UserBaseConsts.UNIT_TYPE_104 == unitType) {
                                    ctUnit.setCourtStatus(UserBaseConsts.COURT_STATUS_1);
                                }else {
                                    ctUnit.setCourtStatus(UserBaseConsts.COURT_STATUS_0);
                                }
                                // 组织名称
                                ctUnit.setUnitName(unitName);
                                // 组织描述
                                if (UserBaseConsts.UNIT_GRADE_3 == unitGrade && UserBaseConsts.UNIT_TYPE_102 == unitType) {
                                    ctUnit.setUnitName(roadName+unitName);
                                    ctUnit.setUnitDes(roadName + "-" + unitName);
                                } else if (UserBaseConsts.UNIT_GRADE_3 == unitGrade && UserBaseConsts.UNIT_TYPE_106 == unitType) {
                                    ctUnit.setUnitName(roadName+unitName);
                                    ctUnit.setUnitDes(roadName + "-" + unitName);
                                } else if (UserBaseConsts.UNIT_GRADE_2 == unitGrade && UserBaseConsts.UNIT_TYPE_102 == unitType) {
                                    ctUnit.setUnitName(roadName+unitName);
                                    ctUnit.setUnitDes(roadName + "-" + unitName);
                                } else if (UserBaseConsts.UNIT_GRADE_2 == unitGrade && UserBaseConsts.UNIT_TYPE_104 == unitType) {
                                    ctUnit.setUnitName(roadName+unitName);
                                    ctUnit.setUnitDes(roadName + "-" + unitName);
                                } else if (UserBaseConsts.UNIT_GRADE_2 == unitGrade && UserBaseConsts.UNIT_TYPE_105 == unitType) {
                                    ctUnit.setUnitName(roadName+unitName);
                                    ctUnit.setUnitDes(roadName + "-" + unitName);
                                } else {
                                    ctUnit.setUnitDes(unitName);
                                }
                                ctUnit.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                                ctUnit.setProv(GzRegionBaseEnum.PROV_1.getIndex());
                                ctUnit.setProvName(GzRegionBaseEnum.PROV_1.getDes());
                                ctUnit.setCity(GzRegionBaseEnum.CITY_1.getIndex());
                                ctUnit.setCityName(GzRegionBaseEnum.CITY_1.getDes());
                                ctUnit.setArea(area);
                                ctUnit.setAreaName(areaName);
                                // 查询街道编码
                                if (UserBaseConsts.UNIT_GRADE_3 == unitGrade || UserBaseConsts.UNIT_GRADE_4 == unitGrade) {
                                    ctUnit.setRoad(roadSyRegion.getId());
                                    ctUnit.setRoadName(roadName);
                                    // 村级编码
                                    if (UserBaseConsts.UNIT_GRADE_4 == unitGrade) {
                                        syRegionQueryWrapper.clear();
                                        syRegionQueryWrapper.eq("parent_id", ctUnit.getRoad()).like("name", unitName.replace("居委会", ""));
                                        SyRegion villageSyRegion = syRegionService.getOne(syRegionQueryWrapper);
                                        if (ObjectUtils.isNotEmpty(villageSyRegion)) {
                                            ctUnit.setVillage(villageSyRegion.getId());
                                            ctUnit.setVillageName(villageSyRegion.getName());
                                        }
                                    }
                                }
                                ctUnit.setAddr(addr);
                                ctUnit.setFindStatus(UserBaseConsts.FIND_STATUS_0);
                                ctUnit.setDispStatus(UserBaseConsts.DISP_STATUS_0);
                                ctUnit.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                                ctUnit.setCustId(custId);
                                ctUnit.setCreateTime(nowDate);
                                ctUnit.setUpdateTime(nowDate);
                                try {
                                    ctUnitService.save(ctUnit);
                                } catch (Exception e) {
                                    errorInfo = errorInfo+unitName+";";
                                    log.error("liyj添加单位报错", e);
                                }
                            }else {
                                ctUnit = ctUnitList.get(0);
                            }
                            // 新增人员
                            if (StringUtils.isEmpty(trueName)) {
                                QueryWrapper<CtUser> ctUserQueryWrapper = new QueryWrapper<>();
                                ctUserQueryWrapper.eq("true_name", trueName)
                                        .eq("idcard", idcard);
                                List<CtUser> ctUserList = ctUserService.list(ctUserQueryWrapper);
                                if (CollectionUtils.isEmpty(ctUserList)) {
                                    CtUser ctUser = new CtUser();
                                    ctUser.setId(utilsClient.getNewTimeId());
                                    ctUser.setTrueName(trueName);
                                    ctUser.setAcc(mobile);
                                    if (StringUtils.isNotBlank(idcard)) {
                                        ctUser.setMobile(mobile);
                                    }
                                    ctUser.setIdcard(idcard);
                                    ctUser.setUnitId(ctUnit.getId());
                                    ctUser.setUnitName(ctUnit.getUnitName());
                                    ctUser.setCreateTime(nowDate);
                                    ctUser.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                                    ctUser.setRealStatus(UserBaseConsts.REAL_STATUS_0);
                                    ctUser.setStatus(UserBaseConsts.USER_STATUS_1);
                                    ctUser.setFindStatus(UserBaseConsts.FIND_STATUS_0);
                                    ctUser.setDispStatus(UserBaseConsts.DISP_STATUS_0);
                                    ctUser.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                                    ctUser.setCustId(custId);
                                    ctUser.setCreateTime(nowDate);
                                    ctUser.setUpdateTime(nowDate);
                                    ctUserService.save(ctUser);
                                    // 新增人员账号
                                    CtAccount ctAccount = new CtAccount();
                                    ctAccount.setId(utilsClient.getNewTimeId());
                                    ctAccount.setCustId(ctUser.getCustId());
                                    ctAccount.setUserId(ctUser.getId());
                                    ctAccount.setAccType(UserBaseConsts.ACC_TYPE_1);
                                    ctAccount.setAcc(ctUser.getAcc());
                                    ctAccount.setCipher(DigestUtils.md5DigestAsHex(cipher.getBytes()));
                                    ctAccount.setCipherOpen(cipher);
                                    ctAccount.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
                                    ctAccount.setCustId(custId);
                                    ctAccount.setCreateTime(nowDate);
                                    ctAccount.setCipherTime(nowDate);
                                    ctAccount.setUpdateTime(nowDate);
                                    ctAccountService.save(ctAccount);
                                    // 新增人员角色关系-单位管理员
                                    CtUserole ctUserole1 = new CtUserole();
                                    ctUserole1.setId(utilsClient.getNewTimeId());
                                    ctUserole1.setUserId(ctUser.getId());
                                    ctUserole1.setRoleId(RoleBaseEnum.ROLE_3.getIndex());
                                    ctUserole1.setRoleCode(RoleBaseEnum.ROLE_3.getIndex());
                                    ctUserole1.setRoleName(RoleBaseEnum.ROLE_3.getDes());
                                    ctUserole1.setCustId(custId);
                                    ctUserole1.setCreateTime(nowDate);
                                    ctUserole1.setUpdateTime(nowDate);
                                    ctUseroleService.save(ctUserole1);
                                    // 新增人员角色关系-纠纷化解人员
                                    CtUserole ctUserole2 = new CtUserole();
                                    ctUserole2.setId(utilsClient.getNewTimeId());
                                    ctUserole2.setUserId(ctUser.getId());
                                    ctUserole2.setRoleId(RoleBaseEnum.ROLE_4.getIndex());
                                    ctUserole2.setRoleCode(RoleBaseEnum.ROLE_4.getIndex());
                                    ctUserole2.setRoleName(RoleBaseEnum.ROLE_4.getDes());
                                    ctUserole2.setCustId(custId);
                                    ctUserole2.setCreateTime(nowDate);
                                    ctUserole2.setUpdateTime(nowDate);
                                    ctUseroleService.save(ctUserole2);
                                }
                            }
                        } catch (Exception e) {
                            errorInfo = errorInfo+r+"行,";
                            log.error("liyj解析报错1", e);
                            continue;
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("liyj解析报错2", e);
            throw new ServiceException("ExcelOperCtunitService.inputByExcel250304", e);
        }finally {
            log.info("报错数据:"+errorInfo);
        }
    }
 
}