xieb
2023-08-09 f242fe10be0391a5dd2510a9633ca61cb0011bf9
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
package cn.gistack.system.user.sync.controller;
 
import cn.gistack.system.user.entity.User;
import cn.gistack.system.user.service.IUserService;
import cn.gistack.system.user.sync.dto.AccountBean;
import cn.gistack.system.user.sync.dto.ApiPushDTO;
import cn.gistack.system.user.sync.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @PROJECT_NAME: skjcmanager
 * @DESCRIPTION: 统一登陆平台用户同步
 * @USER: aix
 * @DATE: 2023/8/7 16:48
 */
@NonDS
@RestController
@RequestMapping("/sync")
@AllArgsConstructor
public class UserPushController {
 
    private final IUserService userService;
 
    private final static String appId = "46a23e7c5fe54f46a37848dc740dc001";
    private final static String appSecret = "AxVGmJcsfxEx36zptmr8J+sv7MAhL1mUuwrk4woGUrM=";
 
    private final static String method = "post";
 
    @PostMapping("/userpush")
    public Object userPush(@RequestBody ApiPushDTO apiPushDTO, HttpServletRequest request) {
        System.out.println("请求参数:" + JSON.toJSONString(apiPushDTO));
        System.out.println("request:" + request);
        System.out.println("request rui:" + request.getRequestURL());
        System.out.println("request.getQueryString():" + request.getQueryString());
        String syncData = SecurityUtil.decryptAES(apiPushDTO.getSyncData(), MD5Util.getMD5String(appSecret));
        List<AccountBean> accountBeanList = JSONArray.parseArray(syncData, AccountBean.class);
 
        //循环list
        accountBeanList.forEach(accountBean -> {
            //判断手机号是否在库中
            User params = new User();
            params.setPhone(accountBean.getPrincipalId());
            User one = userService.getOne(Condition.getQueryWrapper(params));
 
            if (one == null){
                //不在,看status状态,若为1则不操作。0添加进库
                if (accountBean.getStatus().equals("0")){
 
                    User saveUser = new User();
                    //设置id为手机号
//                    saveUser.setId(Long.parseLong(accountBean.getPrincipalId()));
                    //账号为手机号
                    saveUser.setAccount(accountBean.getPrincipalId());
                    saveUser.setPhone(accountBean.getPrincipalId());
                    //设置姓名
                    saveUser.setRealName(accountBean.getAttributes().get("realName"));
                    //设置部门(默认给省)
                    saveUser.setDeptId("420000000000");
                    //设置角色(权限与市州水库管理业务人员一致)
                    saveUser.setRoleId("1688732764750766082");
                    //设置租户id
                    saveUser.setTenantId("000000");
                    userService.save(saveUser);
                }
            }else {
                //在,看status状态,若为1则删除用户。0更新?
                if (accountBean.getStatus().equals("1")){
                    userService.removeUser(accountBean.getPrincipalId());
                } else { //更新
                    //设置姓名
                    one.setRealName(accountBean.getAttributes().get("realName"));
                    userService.updateUser(one);
                }
            }
        });
        Map<String,Object> ret = new HashMap<>();
        ret.put("code", 1000);
        ret.put("msg", "成功");
        ret.put("data", apiPushDTO.getSign());
        return ret;
    }
 
//    public static void main(String[] args) {
//        Map<String,String> attributes = new HashMap<>();
//        // "staffCode": "15563378977",
//        //        "realName": "zhliu",
//        //        "email": null,
//        //        "phone": "15563378977",
//        //        "employeeNum": "zhliu",
//        //        "idCard": null,
//        //        "employeeStatus": "1",
//        //        "userType": "0",
//        //        "sort": "1"
//        attributes.put("staffCode","15563378977");
//        attributes.put("realName","zhliu");
//        attributes.put("email",null);
//        attributes.put("phone","15563378977");
//        attributes.put("employeeNum","zhliu");
//        attributes.put("idCard", null);
//        attributes.put("employeeStatus","1");
//        attributes.put("userType","0");
//        attributes.put("sort","1");
////        String syncData = SecurityUtil.encryptAES(JSON.toJSONString(attributes), MD5Util.getMD5String(appSecret));
////        System.out.println("加密后:" + syncData);
////        String jiemi  = SecurityUtil.decryptAES(syncData, MD5Util.getMD5String(appSecret));
////        System.out.printf("解密后:" + jiemi);
//
////        String tmp = "XmcEvdSFwXYvpAcoDZW5NKYmx1IyvXEJLdRnwLFTBUAhN0DheUZnVMb5y3IuMoASUsBrb82PrbKefa754brKNgvgmKvJxehhkLAWALy/33jX7lA+YjXLzWqLrr/fp6AEVEcLuz8rf+ZvkHcJsyAzPclaxPvd6R0LV0KIiyalnVbhfGCjPPvhYNnOBZh3vNPssn1Z+REywWtHD15G9/zEhpuEno6gPtNxtk1PoqxebCuxZvKRGT2DM/KL0GO4dpY8ksm6bgDcHXcB5oKIdwxb1N7yRQ5DJsIZkz9e/Zo720ObReXCLI9KdErQyOM/uxTqnHE7FVeGP3f5sebTH2WeKyI2mefwGrZYrnGAfxbZOr8pDpXiDs/SF35SHdvC5rRAgfEMm9r1pA74xtb9vplcmvQQqB7aDMbRLQWOo3R9U4KqwU2yvq1L6pZLeWbFVKH5ei40APzcdGS3K8QpcfyzkU5BuR4VgHvNMS9xEkIAbZ9flLBEPE08CReEQ9rJQr8AP5SZ4d394aIxJnJHRxwCNUuMMEdj0/C8UDfwwQMxUQPDlc4tA+DHDjgAwc641gu8IVTqmWjb5+kT3v0Xe9pEPgg4C9kDn0JOoZxsG0UpHdWU5QObGhI+i/j9Ip1T2pcvJdy0eAU0HSAtfBu56i/Li9L97jqtWSog05H3ni3mLjbFrDBARfEd4mOSW9F89fya7ORMM/SnW0qD+Db9dS8Uu/eKdpct/xm4i74HbknnUEdr85txKh0QSNahkirT88yot4YJTPNKOMRQQKrLgj5nAopZIqaoOHvHaTNR6ii0Se8TLrUeUwEYdoW/dpB/3ql5nt34igYLSdll7jw3jRHTHZ6oqvd7CGyQvqSdimcq/BCitx2TkorxMDvoawjYm++eCjW6CDHC2gl4P4e8yf2R5yIjEMxBlU7daMZAcGjY2IO0/WXmW0lbpBXwydHiSSW3oTEL/pwGEFszW2mocMmyB5V2jce8xt4Kog2s1hjNuISZ7J5QIWph0SXONELyCpMud1wFxWpj6o1nZGSV/yzZhTfgk+yEItgRYlDnAEew8lTKSTaOX97/G2Xc1fJZFYYzOuVhtzakrJ3LUjxYEOKr5+NkEx0utKt3UV7o5oH7RB2lvpjREZ5vnvZDIDAWpBnH0thYaq2s2a7KJj92gbgWAjbyFVK2RIOREs3Lw0SxWUh2hfwCPNj7oXzS+X7vwmf4R3aw2vfI20sLKbhyezGKFgmtHQkn1lvdbMDj7hNfNXG6UE698Fa6Fq2Vr7DhPdlAZVmrHiPPaRSKi6QlOaeNtGe8J3PrJpYbtlDV/e8+DRA0kAcrofhktiOFjQcOMY0Gu3qJt6tV4L1ODndZCHdmWIytMsyAB+tEoeEFhIMpWZAzosCws+Kx78L/Uy7t/LwDP+vlN5RoFQnjeAdZTMtriNDmG+8KqrOWOz4EM5uMICro7bbuMBxpAZkV348dlUoQZkzd8jog0f2NkAygL+qIWeQtcOrjYU5S00q9LVd2swK1szpOIaRFbq8YIWLKaEWhPDZIJmtYYhlKIHJ3D0bJ0HoiENjSLyYYEEVmQF4j9wmIBvcyIr46NDF47Jo9K8hVNJObc41qecxh2kiqNh3lST50rgdma5uOJH1dsnS4gYCYWM6jY/8JMLEoqhTO//ljcI9XpnvzSN3F1jkhCJtV7yhBN20wczEdSB63VFxwQU5C5MEbfiLs0kXhgogXQ4e9";
////        String jiemi2  = SecurityUtil.decryptAES(tmp, MD5Util.getMD5String(appSecret));
////        System.out.printf("解密后:" + jiemi2);
//
//
//        System.out.println("sign:" + SignBuilder.create(appId,appSecret).sign());
//
//
//
//    }
 
}