智慧保安后台管理-外网
Administrator
2022-06-30 a9943ed22bd7568924bf98c462139269d873cd8a
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
 
package org.springblade.modules.securitypaper.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.utils.IdCardNoUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.modules.FTP.Result;
import org.springblade.modules.exam.entity.ExamScore;
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.excel.PaperExcel;
import org.springblade.modules.securitypaper.excel.SecurityPaperExcel;
import org.springblade.modules.securitypaper.mapper.SecurityPaperMapper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserDeptService;
import org.springblade.modules.system.service.MyAsyncService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 保安员证管理服务实现类
 * @author zhongrj
 * @since 2021-12-25
 */
@Service
@AllArgsConstructor
public class SecurityPaperServiceImpl extends ServiceImpl<SecurityPaperMapper, SecurityPaper> implements SecurityPaperService {
 
    private final MyAsyncService myAsyncService;
 
    private final IUserDeptService userDeptService;
 
    private final RedisTemplate redisTemplate;
 
//    /**
//     * 导入保安员证数据
//     * @param data
//     * @param isCovered
//     * @param deptId
//     */
//    @Override
//    public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) {
//        //需要推送内网的保安员信息集合
//        List<User> userList = new ArrayList<>();
//        //年龄不符的保安员信息存入集合
//        List<String> cardErrorList = new ArrayList<>();
//        boolean flag = false;
//        for (SecurityPaperExcel paperExcel : data) {
//            User user = Objects.requireNonNull(BeanUtil.copy(paperExcel, User.class));
//            //设置部门id
//            String deptIds = userDeptService.selectIn(user.getDeptId());
//            if (null!=deptIds && !deptIds.equals("")) {
//                user.setDeptId(deptIds);
//            }else {
//                //如果deptIds 为空,则说明还没有改公司
//                throw new ServiceException("导入失败!公司名:["+user.getDeptId()+"]不存在!");
//            }
//
//            //身份证校验
//            if (null==user.getCardid() || user.getCardid().equals("")){
//                throw new ServiceException("导入失败!身份证号码不能为空!");
//            }
//            //身份证住址校验
//            if (null==user.getRegistered() || user.getRegistered().equals("")){
//                throw new ServiceException("导入失败!身份证住址不能为空!");
//            }
//            if (null!=user.getCardid() && !user.getCardid().equals("")){
//                //去除所有空格
//                String cardid = user.getCardid().replaceAll(" ", "");
//                //校验
//                boolean b = IdCardNoUtil.checkIdCardNo(cardid);
//                if(b){
//                    user.setCardid(cardid);
//                }else {
//                    flag = true;
//                    cardErrorList.add(user.getCardid());
////                        throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
//                    continue;
//                }
//            }
//
//            // 设置租户ID
//            user.setTenantId("000000");
//            //默认在职
//            user.setStatus(1);
//            user.setIsDeleted(0);
//            //分配保安角色
//            user.setRoleId("1412226235153731586");
//
//            //默认设置未持证
//            user.setHold("2");
//
//            //性别
//            if (IdCardNoUtil.getSex(paperExcel.getCardid()).equals("男")) {
//                user.setSex(1);
//            }else {
//                user.setSex(2);
//            }
//
//            //设置账号
//            String realName = user.getRealName();
//            String cardid = user.getCardid();
//            user.setAccount(realName.substring(0,1)+cardid.substring(cardid.length()-4));
//            //加密
//            user.setPassword(DigestUtil.encrypt(user.getCardid().substring(user.getCardid().length() - 6)));
//            user.setCreateTime(new Date());
//            user.setUpdateTime(new Date());
//            user.setDispatch("1");
//            //待审查
//            user.setExaminationType("2");
//
//            //推送内网的数据
//            User user0 = Objects.requireNonNull(BeanUtil.copy(user,User.class));
//
//            //生成随机数
//            String uuid = UUID.randomUUID().toString();
//            //将 user 存入 redis
//            redisTemplate.opsForValue().set(uuid, JSON.toJSONString(user));
//            //user0 临时设置uuid 到 reason_for_leav 离职原因字段
//            user0.setReasonForLeav(uuid);
//            //加入集合
//            userList.add(user0);
//        }
//
//        //用户批量插入
//        if (userList.size()>0) {
//            //生成随机数
//            String uuid = UUID.randomUUID().toString();
//            //数据推送
//            Map<String, Object> map = new HashMap<>(1);
//            map.put(uuid, userList);
//            myAsyncService.FTPSecurityPaperAndUserImport(map);
//        }
//
//        //如果所有数据导入有一个异常
//        StringBuilder errorBuilder = new StringBuilder();
//        if (flag){
//            String errorAccount = StringUtils.join(cardErrorList, "\\\n");
//            errorBuilder.append("用户:[" + errorAccount + "]导入失败!身份证号码不正确,请核对!");
//        }
//
//        //抛出异常
//        if (errorBuilder.length()>0){
//            throw new ServiceException(errorBuilder.toString());
//        }
//
//    }
//
 
    /**
     * 导入保安员证数据
     * @param data
     * @param isCovered
     * @param deptId
     */
    @Override
    public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) {
        if (data.size()>0){
            for (SecurityPaperExcel securityPaperExcel : data) {
                //去内网生成保安证编号,由内网生成,无需返回
                //数据推送
                Map<String, Object> map = new HashMap<>(1);
                ExamScore examScore = new ExamScore();
                examScore.setUserId(securityPaperExcel.getId());
                examScore.setExamId("0");
                examScore.setApplyId(0L);
                map.put("key",examScore);
                myAsyncService.FTPSecurityNumberBit(map);
            }
        }
    }
 
    /**
     * 批量导入证件数据
     * @param data
     * @param isCovered
     */
    @Override
    public void importPaper(List<PaperExcel> data, Boolean isCovered) {
        if (data.size()>0){
            for (PaperExcel paperExcel : data) {
                //设置信息
                String sql = "insert into sys_security_paper(number,create_time,people_name,id_card_no,source) " +
                    "values(" + "'" + paperExcel.getNumber() + "'" + "," +
                    "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "'" + "," +
                    "'" + paperExcel.getRealName() + "'" + "," +
                    "'" + paperExcel.getCardid() + "'" + ",3)";
                System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "保安员证编号导入sql = " + sql);
                //数据推送
                myAsyncService.FTP(sql);
            }
        }
    }
}