|
|
@@ -0,0 +1,170 @@
|
|
|
+package com.uas.eis.serviceImpl;
|
|
|
+
|
|
|
+import com.alibaba.druid.util.HttpClientUtils;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dto.YongHResp;
|
|
|
+import com.uas.eis.entity.Employee;
|
|
|
+import com.uas.eis.utils.FlexJsonUtil;
|
|
|
+import com.uas.eis.utils.HttpUtil;
|
|
|
+import com.uas.eis.utils.PinyinUtils;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class YongHService {
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+ @Autowired
|
|
|
+ private UasSyncService uasSyncService;
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+
|
|
|
+ public Map<String, Object> syncEmployee() throws Exception {
|
|
|
+ Map<String, Object> modelMap = new HashMap<String, Object>();
|
|
|
+ //获取token
|
|
|
+ String token=getToken();
|
|
|
+ int add_count_success=0;
|
|
|
+ int add_count_failed=0;
|
|
|
+ int del_count_success=0;
|
|
|
+ int del_count_failed=0;
|
|
|
+ if(StringUtil.hasText(token)){
|
|
|
+ List<Employee> employeeDel = uasSyncService.getYongHDelUserList();
|
|
|
+ for (Employee employee : employeeDel) {
|
|
|
+ boolean bool1=delYongHAccount(token,employee);
|
|
|
+ if(bool1){
|
|
|
+ del_count_success++;
|
|
|
+ }else{
|
|
|
+ del_count_failed++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Employee> employeeAdd = uasSyncService.getYongHAddUserList();
|
|
|
+ for (Employee employee : employeeAdd) {
|
|
|
+ boolean bool2=addYongHAccount(token,employee);
|
|
|
+ if(bool2){
|
|
|
+ add_count_success++;
|
|
|
+ }else{
|
|
|
+ del_count_failed++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String message="添加成功:"+add_count_success+",添加失败:"+add_count_failed+",删除成功:"+del_count_success+",删除失败:"+del_count_failed;
|
|
|
+ modelMap.put("message", message);
|
|
|
+ modelMap.put("success", true);
|
|
|
+ logout(token);
|
|
|
+ }else{
|
|
|
+ modelMap.put("message", "获取token失败!");
|
|
|
+ modelMap.put("success", false);
|
|
|
+ }
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
+ private boolean delYongHAccount(String token,Employee employee) throws Exception {
|
|
|
+ String action="http://172.16.0.207:8081/bi/api?action=delNode&token="+token;
|
|
|
+ Map<String,Object> xmlData = new HashMap<>();
|
|
|
+ Map<String,Object> user = new HashMap<>();
|
|
|
+ user.put("name",employee.getEm_yonghongid());
|
|
|
+ xmlData.put("user",user);
|
|
|
+ String param="xmlData="+FlexJsonUtil.toJsonDeep(xmlData);
|
|
|
+ HttpUtil.Response response =HttpUtil.doPost( action, param, false, null,300000);
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK.value()){
|
|
|
+ System.out.println("delUser成功");
|
|
|
+ String res = response.getResponseText();
|
|
|
+ System.out.println(res);
|
|
|
+ YongHResp resp= FlexJsonUtil.fromJson(res, YongHResp.class);
|
|
|
+ if("1".equals(resp.getResults().getResult().getLevel())){
|
|
|
+ baseDao.updateByCondition("employee","em_isyonghong=0,EM_YONGHONGID=''","em_code='"+employee.getEm_code()+"'");
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong删除用户失败,token:{},message:{}",token,resp.getResults().getResult().getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong删除用户请求失败:{}",response.getResponseText());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private boolean addYongHAccount(String token,Employee employee) throws Exception {
|
|
|
+ String action="http://172.16.0.207:8081/bi/api?action=saveNode&type=user&token="+token;
|
|
|
+ Map<String,Object> xmlData = new HashMap<>();
|
|
|
+ Map<String,Object> info = new HashMap<>();
|
|
|
+ Map<String,Object> user = new HashMap<>();
|
|
|
+ String name=PinyinUtils.getCustomPinyin(employee.getEm_name());
|
|
|
+ user.put("name",name);
|
|
|
+ user.put("pass",employee.getEm_password());
|
|
|
+ user.put("email",employee.getEm_email());
|
|
|
+ user.put("alias",employee.getEm_name());
|
|
|
+ user.put("parent","");
|
|
|
+ user.put("roles","everyone_role");
|
|
|
+ user.put("type",2);
|
|
|
+ info.put("user",user);
|
|
|
+ xmlData.put("info",info);
|
|
|
+ String param="xmlData="+FlexJsonUtil.toJsonDeep(xmlData);
|
|
|
+ HttpUtil.Response response =HttpUtil.doPost( action, param, false, null,300000);
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK.value()){
|
|
|
+ System.out.println("addUser成功");
|
|
|
+ String res = response.getResponseText();
|
|
|
+ System.out.println(res);
|
|
|
+ YongHResp resp= FlexJsonUtil.fromJson(res, YongHResp.class);
|
|
|
+ if("1".equals(resp.getResults().getResult().getLevel())){
|
|
|
+ baseDao.updateByCondition("employee","EM_YONGHONGID='"+name+"'","em_code='"+employee.getEm_code()+"'");
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong添加用户失败,token:{},message:{}",token,resp.getResults().getResult().getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong添加用户请求失败:{}",response.getResponseText());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getToken() throws Exception {
|
|
|
+ String action="http://172.16.0.207:8081/bi/api?action=login";
|
|
|
+ HashMap<String, String> header=new HashMap<>();
|
|
|
+ Map<String,String> paraMap=new HashMap<>();
|
|
|
+ paraMap.put("adminv","admin");
|
|
|
+ paraMap.put("passv","Yonghong123");
|
|
|
+ HttpUtil.Response response=HttpUtil.sendPostRequest(action,header,paraMap);
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK.value()){
|
|
|
+ System.out.println("获取成功");
|
|
|
+ String res = response.getResponseText();
|
|
|
+ YongHResp resp= FlexJsonUtil.fromJson(res, YongHResp.class);
|
|
|
+ if("1".equals(resp.getResults().getResult().getLevel())){
|
|
|
+ String token=resp.getResults().getResult().getMessage();
|
|
|
+ System.out.println(token);
|
|
|
+ return token;
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong获取Token失败,{}",resp.getResults().getResult().getMessage());
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong获取Tokenq请求失败:{}",response.getResponseText());
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void logout(String token) throws Exception {
|
|
|
+ String action="http://172.16.0.207:8081/bi/api?action=logout";
|
|
|
+ HashMap<String, String> header=new HashMap<>();
|
|
|
+ Map<String,String> paraMap=new HashMap<>();
|
|
|
+ paraMap.put("token","token");
|
|
|
+ HttpUtil.Response response=HttpUtil.sendPostRequest(action,header,paraMap);
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK.value()){
|
|
|
+ System.out.println("logout成功");
|
|
|
+ String res = response.getResponseText();
|
|
|
+ YongHResp resp= FlexJsonUtil.fromJson(res, YongHResp.class);
|
|
|
+ if("1".equals(resp.getResults().getResult().getLevel())){
|
|
|
+ logger.info("yonghong-logout success,token{},message:{}",token,resp.getResults().getResult().getMessage());
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong-logout fail,token{},message:{}",token,resp.getResults().getResult().getMessage());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ logger.info("yonghong-logout-请求失败:{}",response.getResponseText());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|