钟日健
2022-04-27 089984eda48375109083903548770dd92b2f8465
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 org.springblade.modules.FTP;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import liquibase.pro.packaged.M;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
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 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);
            //获取 uuid
            String uuid = user1.getReasonForLeav();
            //用户数据校验
            Result result = userCheckOut(user1);
            System.out.println("result = " + result);
            //创建返回对象
            Result result1 = new Result();
            if (result.getCode()==200){
                user1.setReasonForLeav("");
                //校验保安员证编号
                Result result2 = hanlder.checkSecurityNumber(user1);
                //去新增
                hanlder.userService.save(result2.getUser());
 
                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());
                //校验保安员证编号
                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);
            //向外网发送数据
            FtpUtil.objectFileUpload(map1);
        }
    }
 
    /**
     * 用户校验
     * @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(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 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() + "'" +
                "," + "'" + experience.getCardid() + "'" +
                "," + "'" + experience.getCompanyname() + "'" +
                "," + "'" + experience.getSecurityid() + "'"
                + ")";
            myAsyncService.FTP(s);
        }
    }
 
    /**
     * 保安员证编号校验
     * @param user
     * @return
     */
    public Result checkSecurityNumber(User user){
        //2.保安证编号校验
        //判断是否持证
        boolean states = false;
        if (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");
            }
        }
 
        if (!states) {
            return new Result(201,null,"保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!",user);
        }
 
        return new Result(200,null,"",user);
    }
 
 
}