guoshilong
2023-08-09 34c2f71c21bc56b359b27ad92061477a0ff3ff48
skjcmanager/skjcmanager-service/skjcmanager-user/src/main/java/cn/gistack/system/user/sync/controller/UserPushController.java
@@ -1,20 +1,24 @@
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.SecurityUtil;
import cn.gistack.system.user.sync.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.IResultCode;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @PROJECT_NAME: skjcmanager
@@ -28,12 +32,91 @@
@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 R userPush(ApiPushDTO apiPushDTO) {
      String syncData = SecurityUtil.decryptAES(apiPushDTO.getSyncData(),apiPushDTO.getSign());
   public R userPush(@RequestBody ApiPushDTO apiPushDTO) {
      System.out.println("请求参数:" + JSON.toJSONString(apiPushDTO));
      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);
            }
         }
      });
      return R.data(apiPushDTO.getTimestamp());
   }
//   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 = "XmcEvdSFwXYvpAcoDZW5NKYmx1IyvXEJLdRnwLFTBUAhN0DheUZnVMb5y3IuMoASUsBr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thYaq2s2a7KJj92gbgWAjbyFVK2RIOREs3Lw0SxWUh2hfwCPNj7oXzS+X7vwmf4R3aw2vfI20sLKbhyezGKFgmtHQkn1lvdbMDj7hNfNXG6UE698Fa6Fq2Vr7DhPdlAZVmrHiPPaRSKi6QlOaeNtGe8J3PrJpYbtlDV/e8+DRA0kAcrofhktiOFjQcOMY0Gu3qJt6tV4L1ODndZCHdmWIytMsyAB+tEoeEFhIMpWZAzosCws+Kx78L/Uy7t/LwDP+vlN5RoFQnjeAdZTMtriNDmG+8KqrOWOz4EM5uMICro7bbuMBxpAZkV348dlUoQZkzd8jog0f2NkAygL+qIWeQtcOrjYU5S00q9LVd2swK1szpOIaRFbq8YIWLKaEWhPDZIJmtYYhlKIHJ3D0bJ0HoiENjSLyYYEEVmQF4j9wmIBvcyIr46NDF47Jo9K8hVNJObc41qecxh2kiqNh3lST50rgdma5uOJH1dsnS4gYCYWM6jY/8JMLEoqhTO//ljcI9XpnvzSN3F1jkhCJtV7yhBN20wczEdSB63VFxwQU5C5MEbfiLs0kXhgogXQ4e9";
//      String jiemi2  = SecurityUtil.decryptAES(tmp, MD5Util.getMD5String(appSecret));
//      System.out.printf("解密后:" + jiemi2);
//
//      SignUtil.getSign(appId, 1L, appSecret, "", "post", attributes);
//
//   }
}