Administrator
2022-06-16 7ad6aa9b637f1d21106266991bf39afee802d652
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
package org.springblade.modules.FTP;
 
import org.json.JSONArray;
import org.json.JSONObject;
import org.springblade.common.utils.DesensitizedUtil;
import org.springblade.common.utils.InvestigateUtil;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.experience.service.IExperienceService;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * @author Administrator
 */
@Service
public class MyAsyncService {
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private IDeptService iDeptService;
 
    @Autowired
    private IExperienceService experienceService;
 
    /**
     * FTP
     * @param s sql语句
     */
    @Async
    public void FTP(String s) {
        FtpUtil.sqlFileUpload(s);
    }
 
    /**
     * FTP 审查结果推送
     * @param s sql语句
     */
    @Async
    public void FTP1(String s,String id) {
        FtpUtil.sqlFileUploadUserExamine(s,id);
    }
 
 
    /**
     * 异步审查新增的保安员
     * @param user0
     */
    @Async
    public void checkUserExamineByCardNo(User user0){
        //如果是保安员
        if (user0.getRoleId().equals("1412226235153731586")){
            //创建用户对象
            User user = new User();
            user.setId(user0.getId());
            //远程调用接口
            String body = InvestigateUtil.httpGetOne(user0.getCardid());
            System.out.println("user0 = " + user0.getCardid());
            JSONObject jsonObject = new JSONObject(body);
            Object data = jsonObject.get("data");
            JSONObject jsonData = new JSONObject(data.toString());
            JSONArray res = jsonData.getJSONArray("res");
            //设置审核时间
            user.setAuditTime(new Date());
            //如果有结果返回
            if (res.length() == 0) {
                //没有数据正常
                user.setExaminationType("0");
            } else {
                int count = 0;
                user.setExaminationType("1");
                for (int i = 0; i < res.length(); i++) {
                    if (res.getJSONObject(i).get("zdrylbjh").toString() != null
                        && res.getJSONObject(i).get("zdrylbjh").toString() != ""
                        && res.getJSONObject(i).get("zdrylbjh").toString() != "null"
                    ) {
                        user.setExaminationMx(res.getJSONObject(i).get("zdrylbjh").toString());
                        //更新用户数据
//                        userService.updateById(user);
                        break;
                    }
                    if (res.getJSONObject(i).get("zdryxlmc").toString() != null
                        && res.getJSONObject(i).get("zdryxlmc").toString() != ""
                        && res.getJSONObject(i).get("zdryxlmc").toString() != "null"
                    ) {
                        user.setExaminationMx(res.getJSONObject(i).get("zdryxlmc").toString());
                        //更新用户数据
//                        userService.updateById(user);
                        break;
                    }
                    if (res.getJSONObject(i).get("ztrylx").toString() != null
                        && res.getJSONObject(i).get("ztrylx").toString() != ""
                        && res.getJSONObject(i).get("ztrylx").toString() != "null"
                    ) {
                        user.setExaminationMx(res.getJSONObject(i).get("ztrylx").toString());
                        //更新用户数据
//                        userService.updateById(user);
                        break;
                    }
                    count++;
                    //条件中的数据都为空,则审查为正常
                    if (count==res.length()){
                        //更新用户数据,设为正常
                        user.setExaminationType("0");
//                        userService.updateById(user);
                    }
                }
            }
            //更新用户数据
            userService.updateById(user);
            //同时更新外网用户信息
            String s1 = "update blade_user set examination_type = " + user.getExaminationType() +
                ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
                " where id = " + "'" + user.getId() + "'";
            FTP1(s1,user.getId().toString());
        }
    }
 
 
    /**
     * 异步新增用户从业记录
     * @param user
     */
    @Async
    public void insertExperience(User user) {
        //根据公司名查询单位
        Dept dept = iDeptService.getById(user.getDeptId());
        Experience experience = new Experience();
        experience.setCompanyname(dept.getDeptName());
        //新增
        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() + "'"
            + ")";
        //向外网推送
        FTP(s);
    }
}