钟日健
2022-04-26 a03c324b7ce6d6f2e4a591a3954f34e597f4194c
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
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.system.entity.User;
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.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Component
public class DataHanlder {
 
    @Autowired
    private IUserService userService;
 
    //声明对象
    private static DataHanlder hanlder;
 
    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        hanlder = this;
        hanlder.userService = this.userService;
    }
 
 
    /**
     * 数据处理
     * @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();
            //用户数据校验
            R result = userCheckOut(user1);
            //创建返回对象
            Result result1 = new Result();
            if (result.getCode()==200){
                user1.setReasonForLeav("");
                //去新增
                hanlder.userService.save(user1);
                //设置返回结果
                result1.setCode(200);
                result1.setUserId(user1.getId());
                result1.setMsg("新增成功");
            }else if (result.getCode()==201){
                //去修改
                user1.setReasonForLeav("");
                User data =(User) result.getData();
                user1.setId(data.getId());
                hanlder.userService.updateById(user1);
                //设置返回结果
                result1.setCode(201);
                result1.setUserId(user1.getId());
                result1.setMsg("修改成功");
            }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
     */
    private static R 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())){
                R.data(400,null,user.getRealName() + "已在其他单位导入");
            }else {
                R.data(201,one,"已在本单位导入");
            }
        }
        return R.data(200,null,"");
    }
 
 
}