Administrator
2022-06-09 dce1659944f682aa8360a7f8867db56cf6eac8e8
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
package org.springblade.modules.FTP;
 
import com.alibaba.fastjson.JSON;
import org.springblade.common.utils.DesensitizedUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.modules.dispatcher.entity.Dispatcher;
import org.springblade.modules.dispatcher.service.IDispatcherService;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.experience.service.IExperienceService;
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Component
public class DataHanlder {
 
    @Autowired
    private IUserService userService;
 
    //声明对象
    private static DataHanlder hanlder;
 
    @Autowired
    private SecurityPaperService securityPaperService;
 
    @Autowired
    private IExperienceService experienceService;
 
    @Autowired
    private IDispatcherService dispatcherService;
 
    @Autowired
    private MyAsyncService myAsyncService;
 
    @Autowired
    private IDeptService iDeptService;
 
 
 
 
    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        hanlder = this;
        hanlder.userService = this.userService;
        hanlder.securityPaperService = this.securityPaperService;
        hanlder.experienceService = this.experienceService;
        hanlder.myAsyncService = this.myAsyncService;
        hanlder.dispatcherService = this.dispatcherService;
        hanlder.iDeptService = this.iDeptService;
    }
 
 
    /**
     * 保安员审查
     * @param json
     */
    public static void handlerUserExamine(String json) {
        User user = JSON.parseObject(json, User.class);
        //获取用户cardid
        User user1 = hanlder.userService.getById(user.getId());
        //用户审查
        hanlder.myAsyncService.checkUserExamineByCardNo(user1);
    }
 
    /**
     * 获取保安员证编号
     * @param json
     */
    public static void handlerSecurityNumerBit(String json) {
        Map map = JSON.parseObject(json, Map.class);
        //取出 key(uuid)
        String key = map.keySet().toArray()[0].toString();
        //编号前缀
        String pre = map.get(key).toString();
        Integer max = hanlder.userService.getSecurityPaperCount(pre);
        Result result = new Result(200, null, max.toString(),null);
        Map<String, Object> map1 = new HashMap<>(1);
        map1.put(key, result);
        //向外网发送数据
        FtpUtil.objectFileUploadSecurityNumberCount(map1);
    }
 
    /**
     * 培训报名数据处理
     * @param json
     */
    public static void handlerListTrain(String json) {
        Map map = JSON.parseObject(json, Map.class);
        //取出 key(uuid)
        String key = map.keySet().toArray()[0].toString();
        Object users = map.get(key);
        List<String > userList = JSON.parseArray(users.toString(), String.class);
        //遍历
        if (userList.size()>0) {
            List<Result> resultList = new ArrayList<>();
            //开始遍历
            for (String userId : userList) {
                //校验用户年龄
                int age = hanlder.userService.getUserAge(Long.parseLong(userId));
                //创建返回对象
                Result result1 = new Result();
                result1.setUserId(Long.parseLong(userId));
                if (age>=18 && age<=60) {
                    //年龄符合要求
                    result1.setCode(200);
                } else {
                    //年龄不符合要求
                    result1.setCode(201);
                }
                //存入结果集
                resultList.add(result1);
            }
            Result result = new Result(200, "", resultList);
            Map<String, Object> map1 = new HashMap<>(1);
            map1.put(key, result);
            //向外网发送数据
            FtpUtil.objectFileUploadListTrain(map1);
        }
    }
 
    /**
     * 数据处理(集合)
     * @param json
     */
    public static void handlerList(String json) {
        Map map = JSON.parseObject(json, Map.class);
        //取出 key(uuid)
        String key = map.keySet().toArray()[0].toString();
        Object users = map.get(key);
        List<User> userList = JSON.parseArray(users.toString(), User.class);
        //遍历
        if (userList.size()>0) {
            List<Result> resultList = new ArrayList<>();
            //创建更新用户集合对象
            List<User> updateUser = new ArrayList<>();
            //开始遍历
            for (User user : userList) {
                //取出 uuid
                String uuid = user.getReasonForLeav();
                //用户数据校验,是否已导入(本单位或其他单位)
                Result result = userCheckOut(user);
                //创建返回对象
                Result result1 = new Result();
                if (result.getCode() == 200) {
                    user.setReasonForLeav("");
                    //校验保安员证编号
                    Result result2 = hanlder.checkSecurityNumber(user);
                    User user1 = result2.getUser();
                    //去新增
                    boolean save = hanlder.userService.save(user1);
                    if (save) {
                        //异步新增从业记录
                        hanlder.myAsyncService.insertExperience(user1);
                        //异步审查
                        hanlder.myAsyncService.checkUserExamineByCardNo(user1);
                    }
 
                    if (result2.getCode() == 200) {
                        //设置返回结果
                        result1.setCode(200);
                        result1.setUserId(user1.getId());
                    } else {
                        //设置返回结果
                        result1.setCode(203);
                        result1.setUserId(user1.getId());
                    }
                } else if (result.getCode() == 201) {
                    //去修改
                    user.setReasonForLeav("");
                    User data = result.getUser();
                    user.setId(data.getId());
                    user.setCreateTime(data.getCreateTime());
                    //校验保安员证编号
                    Result result2 = hanlder.checkSecurityNumber(user);
                    User user2 = result2.getUser();
                    user2.setId(data.getId());
 
                    hanlder.userService.updateById(user2);
                    //设置返回结果
                    if (result2.getCode() == 200) {
                        result1.setCode(201);
                        result1.setUserId(user.getId());
                    } else {
                        //设置返回结果
                        result1.setCode(203);
                        result1.setUserId(user.getId());
                    }
                } else {
                    //不新增,不修改
                    //设置返回结果,以在其他单位存在
                    result1.setCode(202);
                    result1.setUserId(null);
                }
                result1.setMsg(uuid);
                //存入结果集
                resultList.add(result1);
            }
            Result result = new Result(200, "", resultList);
            Map<String, Object> map1 = new HashMap<>(1);
            map1.put(key, result);
            System.out.println("map1 = " + map1);
            //向外网发送数据
            FtpUtil.objectFileUploadList(map1);
        }
    }
 
    /**
     * 数据处理(单个保安员新增)
     * @param json
     */
    public static void handler(String json){
        //以分号分割
        List<String> list = Arrays.asList(json.split(";"));
        //对象转换
        for (String s : list) {
            Map map = JSON.parseObject(s, Map.class);
            Object user = map.get("user");
            User user1 = JSON.parseObject(user.toString(), User.class);
            System.out.println("user1 = " + user1);
 
            //获取 uuid
            String uuid = user1.getReasonForLeav();
            //用户数据校验
            Result result = userCheckOut(user1);
            //创建返回对象
            Result result1 = new Result();
            if (result.getCode()==200){
                user1.setReasonForLeav("");
                //校验保安员证编号
                Result result2 = hanlder.checkSecurityNumber(user1);
                User user2 = result2.getUser();
                //去新增
                boolean save = hanlder.userService.save(user2);
                if (save){
                    //异步新增从业记录
                    hanlder.myAsyncService.insertExperience(user2);
                    //异步审查
                    hanlder.myAsyncService.checkUserExamineByCardNo(user2);
                }
 
                if (result2.getCode()==200){
                    //设置返回结果
                    result1.setCode(200);
                    result1.setUserId(user1.getId());
                    result1.setMsg("新增成功");
                }else {
                    //设置返回结果
                    result1.setCode(203);
                    result1.setUserId(user1.getId());
                    result1.setMsg(result2.getMsg());
                }
 
            }else if (result.getCode()==201){
                //去修改
                user1.setReasonForLeav("");
                User data = result.getUser();
                user1.setId(data.getId());
                user1.setCreateTime(data.getCreateTime());
 
                //校验保安员证编号
                Result result2 = hanlder.checkSecurityNumber(user1);
                User user2 = result2.getUser();
                user2.setId(data.getId());
 
                hanlder.userService.updateById(user2);
                //设置返回结果
                if (result2.getCode()==200) {
                    result1.setCode(201);
                    result1.setUserId(user1.getId());
                    result1.setMsg("修改成功");
                }else {
                    //设置返回结果
                    result1.setCode(204);
                    result1.setUserId(user1.getId());
                    result1.setMsg(result2.getMsg());
                }
            }else {
                //不新增,不修改
                //设置返回结果
                result1.setCode(400);
                result1.setUserId(null);
                result1.setMsg(result.getMsg());
            }
            Map<String, Object> map1 = new HashMap<>(1);
            map1.put(uuid,result1);
            System.out.println("用户新增:开始向外网推送数据............");
            //向外网发送数据
            FtpUtil.objectFileUpload(map1,uuid);
        }
    }
 
    /**
     * 用户校验
     * @param user
     */
    public static Result userCheckOut(User user) {
        //1. 校验是否有重复导入
        User user1 = new User();
        user1.setCardid(user.getCardid());
        user1.setStatus(1);
        user1.setIsDeleted(0);
        User one = hanlder.userService.getOne(Condition.getQueryWrapper(user1));
        if (null!=one){
            //判断单位是否一致
            if (!one.getDeptId().equals(user.getDeptId())){
                //判断是否为机读身份证录入
                if (null!=user.getCell() && !user.getCell().equals("")){
                    if (user.getCell().equals("2")){
                        // cell 2为机读录入
                        //先将原有人员离职
                        one.setStatus(2);
                        one.setUpdateTime(new Date());
                        //离职
                        hanlder.userService.updateById(one);
                        //同步外网
                        String s1 = "update blade_user set status = " + one.getStatus() +
                            ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(one.getUpdateTime()) + "'" +
                            " where id = " + "'" + one.getId() + "'";
                        hanlder.myAsyncService.FTP(s1);
 
                        //人员离职后修改派遣记录,修改从业记录
                        hanlder.updateUserDispatcherExp(one);
                        //返回
                        return new Result(200,null,"");
                    }
                }
                return new Result(400,null,user.getRealName() + "已在其他单位导入");
            }else {
                return new Result(201,"已在本单位导入",one);
            }
        }
        return new Result(200,null,"");
    }
 
    /**
     * 修改派遣记录,修改从业记录
     *
     * @param user
     */
    private void updateUserDispatcherExp(User user) {
        //修改派遣状态
        user.setDispatch("1");
        //同时将派遣记录中的派遣状态修改
        //查询派遣记录(还在派遣中的)
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setUserIds(user.getId().toString());
        dispatcher.setStatus(0);
        List<Dispatcher> dispatcherList = dispatcherService.list(Condition.getQueryWrapper(dispatcher));
        if (dispatcherList.size() > 0) {
            dispatcherList.forEach(dispatcher1 -> {
                dispatcher1.setStatus(1);
                dispatcher1.setUpdateTime(new Date());
                String s1 =
                    "update sys_dispatcher set status = " + "'" + dispatcher1.getStatus() + "'"
                        + ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher1.getUpdateTime()) + "'"
                        + " " + "where id = " + "'" + dispatcher1.getId() + "'";
                myAsyncService.FTP(s1);
            });
        }
 
        //查询当前用户是否有从业记录,没有的话新增,有就更新
        //根据公司名查询单位
        Dept dept = iDeptService.getById(user.getDeptId());
        Experience experience = new Experience();
        experience.setCompanyname(dept.getDeptName());
        //按id降序
        List<Experience> list = experienceService.list(Condition.getQueryWrapper(experience).orderByDesc("id"));
        if (list.size() > 0) {
            //如果有多条取第一条更新
            Experience experience1 = list.get(0);
            //设置离职时间
            experience1.setDeparturetime(new Date());
            //更新从业记录信息
            experienceService.updateById(experience1);
            //数据同步
            String s1 =
                "update sys_experience set departureTime = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience1.getDeparturetime()) + "'"
                    + " " + "where id = " + "'" + experience1.getId() + "'";
            myAsyncService.FTP(s1);
        } else {
            //新增
            if (null != user.getRtime()) {
                experience.setEntrytime(user.getRtime());
            } else {
                experience.setEntrytime(new Date());
            }
            experience.setDeparturetime(new Date());
            experience.setName(user.getRealName());
            if (null != user.getReasonForLeav() && !user.getReasonForLeav().equals("")) {
                experience.setLeaving(user.getReasonForLeav());
            }
            experience.setCardid(user.getCardid());
            experience.setSecurityid(user.getId().toString());
            //新增
            experienceService.save(experience);
 
            // 身份证号脱敏
            String cardid = DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid());
 
            //内网同步
            String s = "insert into sys_experience(id,name,entryTime,departureTime,leaving,cardId,companyname,securityId) " +
                "values(" + "'" + experience.getId() + "'" +
                "," + "'" + experience.getName() + "'" +
                "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
                "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getDeparturetime()) + "'" +
                "," + "'" + experience.getLeaving() + "'" +
                "," + "'" + cardid + "'" +
                "," + "'" + experience.getCompanyname() + "'" +
                "," + "'" + experience.getSecurityid() + "'"
                + ")";
            myAsyncService.FTP(s);
        }
    }
 
    /**
     * 保安员证编号校验
     * @param user
     * @return
     */
    public Result checkSecurityNumber(User user){
        //2.保安证编号校验
        //判断是否持证
        boolean states = false;
        if (null!= user.getHold()
            && user.getHold().equals("1")
            && null!=user.getSecuritynumber()
            && !user.getSecuritynumber().equals("")){
            //持证,校验保安证编号是否合法
            SecurityPaper securityPaper = new SecurityPaper();
            securityPaper.setIdCardNo(user.getCardid());
            List<SecurityPaper> securityPaperList = hanlder.securityPaperService.list(Condition.getQueryWrapper(securityPaper));
            if (securityPaperList.size()>0){
                //遍历
                for (SecurityPaper paper : securityPaperList) {
                    if (paper.getNumber().equals(user.getSecuritynumber())){
                        states = true;
                    }
                }
                if (!states){
                    user.setHold("2");
                }
            }else {
                states = false;
                user.setHold("2");
            }
        }else {
            states = true;
        }
 
        if (!states) {
            return new Result(201,null,"保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!",user);
        }
 
        return new Result(200,null,"",user);
    }
 
 
}