forked from integrated_whb/integrated_whb
				
			PLSUtil工具类优化
							parent
							
								
									0683b752b6
								
							
						
					
					
						commit
						152a6da70d
					
				
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -652,6 +652,94 @@ public class UsersController extends BaseController {
 | 
			
		|||
	 * @return
 | 
			
		||||
	 * @throws Exception
 | 
			
		||||
	 */
 | 
			
		||||
//	@RequestMapping(value="/saveUser")
 | 
			
		||||
//	@RequiresPermissions("user:add")
 | 
			
		||||
//	@ResponseBody
 | 
			
		||||
//	@LogAnno(menuType= "双重预防",menuServer= "企业管理",instructionsOperate = "用户管理",instructionsType = "保存用户")
 | 
			
		||||
//	public Object saveUser() throws Exception{
 | 
			
		||||
//		Map<String,Object> map = new HashMap<String,Object>();
 | 
			
		||||
//		String errInfo = "success";
 | 
			
		||||
//		PageData pd = new PageData();
 | 
			
		||||
//		pd = this.getPageData();
 | 
			
		||||
//		// 默认周期初始值为1
 | 
			
		||||
//		pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
 | 
			
		||||
////		pd.put("DURATION", "1");							//工作状态持续时间
 | 
			
		||||
//		pd.put("WORKSTATUS", "1");							//工作状态
 | 
			
		||||
//		pd.put("WORKPERIOD", "1");							//当前工作周期数
 | 
			
		||||
//		pd.put("RIGHTS", "788664966448");
 | 
			
		||||
//
 | 
			
		||||
//		if(pd.get("USERAVATARURL")!=null && !pd.getString("USERAVATARURL").equals("")){
 | 
			
		||||
////			System.out.println("USERAVATARURL原长度:"+pd.getString("USERAVATARURL").length());
 | 
			
		||||
//			String USERAVATARURL64 = ImageAnd64Binary.zipBase64(pd.getString("USERAVATARURL"));
 | 
			
		||||
////			System.out.println("USERAVATARURL压缩长度:"+USERAVATARURL64.length());
 | 
			
		||||
//			try{
 | 
			
		||||
//				FaceUtil.compareFace(pd.getString("USERAVATARURL"),pd.getString("USERAVATARURL"));
 | 
			
		||||
//			}catch (Exception e){
 | 
			
		||||
//				map.put("result", "fail");
 | 
			
		||||
//				map.put("msg", "人脸图像不符合要求 请重新上传!");
 | 
			
		||||
//				return map;
 | 
			
		||||
//			}
 | 
			
		||||
//		}
 | 
			
		||||
//		if ("input".equals(pd.getString("LEARNERCATEGORYSTATUS"))) {
 | 
			
		||||
//			pd.put("DICTTYPE","APPLICABLE_PERSONNEL");
 | 
			
		||||
//			PageData lc = dictionariesCorpService.saveSelf(pd);
 | 
			
		||||
//			pd.put("LEARNERCATEGORY", lc.getString("DICTIONARIES_ID"));
 | 
			
		||||
//		}
 | 
			
		||||
//		pd.put("USER_ID", this.get32UUID());			//ID 主键
 | 
			
		||||
//		pd.put("LAST_LOGIN", "");						//最后登录时间
 | 
			
		||||
//		pd.put("IP", "");								//IP
 | 
			
		||||
//		pd.put("STATUS", "0");							//状态
 | 
			
		||||
//		pd.put("ISMAIN", "0");							//状态
 | 
			
		||||
//		pd.put("SKIN", "pcoded-navbar navbar-image-3,navbar pcoded-header navbar-expand-lg navbar-light header-dark,");		//用户默认皮肤
 | 
			
		||||
//		pd.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("USERNAME"), pd.getString("PASSWORD")).toString());			//密码加密
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//		if(null == usersService.findByUsername(pd)){	//判断用户名是否存在
 | 
			
		||||
//				usersService.saveUser(pd); 					//执行保存
 | 
			
		||||
//			if("true".equals(pd.getString("ISSTUDENT"))) {
 | 
			
		||||
//				if ("select".equals(pd.getString("letDutiesType"))) {
 | 
			
		||||
//					pd.put("DUTIES", pd.getString("DUTIES"));
 | 
			
		||||
//				} else {
 | 
			
		||||
//					PageData dicPd = new PageData();
 | 
			
		||||
//					dicPd.put("PARENT_ID", "09e36ac01e9540f8bc84eab1c1a78754");
 | 
			
		||||
//					dicPd.put("BIANMA", "zhiwu");
 | 
			
		||||
//					dicPd.put("NAME", pd.getString("DUTIESValue"));
 | 
			
		||||
//					dicPd = dictionariesCorpService.saveByZidongxinzeng(dicPd);
 | 
			
		||||
//					pd.put("DUTIES", dicPd.getString("DICTIONARIES_ID"));
 | 
			
		||||
//				}
 | 
			
		||||
//				if ("select".equals(pd.getString("letTitleType"))) {
 | 
			
		||||
//					pd.put("TITLE", pd.getString("TITLE"));
 | 
			
		||||
//				} else {
 | 
			
		||||
//					PageData dicPd = new PageData();
 | 
			
		||||
//					dicPd.put("PARENT_ID", "945a6b10e59946078b500f0fbafa8679");
 | 
			
		||||
//					dicPd.put("BIANMA", "zhicheng");
 | 
			
		||||
//					dicPd.put("NAME", pd.getString("letTitleValue"));
 | 
			
		||||
//					dicPd = dictionariesCorpService.saveByZidongxinzeng(dicPd);
 | 
			
		||||
//					pd.put("TITLE", dicPd.getString("DICTIONARIES_ID"));
 | 
			
		||||
//				}
 | 
			
		||||
//				if ("select".equals(pd.getString("letTypeOfWorkType"))) {
 | 
			
		||||
//					pd.put("TYPE_OF_WORK", pd.getString("TYPE_OF_WORK"));
 | 
			
		||||
//				} else {
 | 
			
		||||
//					PageData dicPd = new PageData();
 | 
			
		||||
//					dicPd.put("PARENT_ID", "55484e491a5e442d839c4595380713ec");
 | 
			
		||||
//					dicPd.put("BIANMA", "gongzhong");
 | 
			
		||||
//					dicPd.put("NAME", pd.getString("letTypeOfWorkValue"));
 | 
			
		||||
//					dicPd = dictionariesCorpService.saveByZidongxinzeng(dicPd);
 | 
			
		||||
//					pd.put("TYPE_OF_WORK", dicPd.getString("DICTIONARIES_ID"));
 | 
			
		||||
//				}
 | 
			
		||||
//				userInfoService.save(pd);
 | 
			
		||||
//			}
 | 
			
		||||
//		}else{
 | 
			
		||||
//			map.put("result","failed");
 | 
			
		||||
//		}
 | 
			
		||||
//		FHLOG.save(Jurisdiction.getUsername(), "新增用户:"+pd.getString("USERNAME"));//记录日志
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//		map.put("result", errInfo);				//返回结果
 | 
			
		||||
//		map.put("USER_ID", pd.getString("USER_ID"));				//返回结果
 | 
			
		||||
//		return map;
 | 
			
		||||
//	}
 | 
			
		||||
 | 
			
		||||
	@RequestMapping(value="/saveUser")
 | 
			
		||||
	@RequiresPermissions("user:add")
 | 
			
		||||
	@ResponseBody
 | 
			
		||||
| 
						 | 
				
			
			@ -663,6 +751,7 @@ public class UsersController extends BaseController {
 | 
			
		|||
		PageData pd = this.getPageData();
 | 
			
		||||
		try {
 | 
			
		||||
			usersService.saveUserNew(pd);
 | 
			
		||||
			// 调用 Service 层保存用户
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			errInfo = "error";
 | 
			
		||||
			map.put("msg", e.getMessage());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,20 +1,15 @@
 | 
			
		|||
package com.zcloud.util;
 | 
			
		||||
 | 
			
		||||
import com.alibaba.fastjson.JSONObject;
 | 
			
		||||
import com.zcloud.controller.corp.CorpInfoController;
 | 
			
		||||
import com.zcloud.entity.EmployeeData;
 | 
			
		||||
import com.zcloud.entity.PageData;
 | 
			
		||||
import com.zcloud.service.corp.CorpInfoService;
 | 
			
		||||
import com.zcloud.service.corp.CorpPlsInfoService;
 | 
			
		||||
import com.zcloud.service.system.UsersService;
 | 
			
		||||
import okhttp3.*;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.URLConnection;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public class PLSUtil {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +18,6 @@ public class PLSUtil {
 | 
			
		|||
    @Autowired
 | 
			
		||||
    public static UsersService usersService;
 | 
			
		||||
 | 
			
		||||
    // 修改 getToken 方法以返回布尔值
 | 
			
		||||
    public static boolean getToken(PageData pd) throws Exception {
 | 
			
		||||
        boolean tokenUpdated = false;
 | 
			
		||||
        pd = corpplsinfoService.findById(pd);
 | 
			
		||||
| 
						 | 
				
			
			@ -39,15 +33,7 @@ public class PLSUtil {
 | 
			
		|||
            loginPayload.put("password", passWord);
 | 
			
		||||
            loginPayload.put("isPresentationMode", "2");
 | 
			
		||||
 | 
			
		||||
            OkHttpClient client = new OkHttpClient();
 | 
			
		||||
            MediaType JSON = MediaType.parse("application/json; charset=utf-8");
 | 
			
		||||
            RequestBody body = RequestBody.create(JSON, loginPayload.toJSONString());
 | 
			
		||||
            Request request = new Request.Builder()
 | 
			
		||||
                    .url(loginUrl)
 | 
			
		||||
                    .post(body)
 | 
			
		||||
                    .build();
 | 
			
		||||
 | 
			
		||||
            Response response = client.newCall(request).execute();
 | 
			
		||||
            Response response = sendPostHttpRequest(loginPayload.toJSONString(), loginUrl,null);
 | 
			
		||||
            if (response.isSuccessful()) {
 | 
			
		||||
                String responseBody = response.body().string();
 | 
			
		||||
                JSONObject responseJSON = new JSONObject(responseBody.isEmpty());
 | 
			
		||||
| 
						 | 
				
			
			@ -83,17 +69,7 @@ public class PLSUtil {
 | 
			
		|||
            pd = corpplsinfoService.findById(pd);
 | 
			
		||||
            String token = pd.getString("TOKEN");
 | 
			
		||||
            String url = pd.getString("POST_URL") + "/deploy/psnmgmt/insertPsnInfo";
 | 
			
		||||
 | 
			
		||||
            OkHttpClient client = new OkHttpClient();
 | 
			
		||||
            MediaType JSON = MediaType.parse("application/json; charset=utf-8");
 | 
			
		||||
            RequestBody body = RequestBody.create(JSON, employeeData.toString());
 | 
			
		||||
            Request request = new Request.Builder()
 | 
			
		||||
                    .url(url)
 | 
			
		||||
                    .post(body)
 | 
			
		||||
                    .addHeader("Authorization", "Bearer " + token)
 | 
			
		||||
                    .build();
 | 
			
		||||
 | 
			
		||||
            Response response = client.newCall(request).execute();
 | 
			
		||||
            Response response = sendPostHttpRequest(url,employeeData.toString(),token);
 | 
			
		||||
            if (!response.isSuccessful()) {
 | 
			
		||||
                throw new IOException(String.valueOf(response));
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -101,4 +77,43 @@ public class PLSUtil {
 | 
			
		|||
            throw new Exception("无法获取有效的Token");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Response sendPostHttpRequest(String url, String jsonPayload, String token) throws IOException {
 | 
			
		||||
        OkHttpClient client = new OkHttpClient();
 | 
			
		||||
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
 | 
			
		||||
        RequestBody body = RequestBody.create(JSON, jsonPayload);
 | 
			
		||||
        Request.Builder builder = new Request.Builder()
 | 
			
		||||
                .url(url)
 | 
			
		||||
                .post(body);
 | 
			
		||||
 | 
			
		||||
        if (token != null && !token.isEmpty()) {
 | 
			
		||||
            builder.addHeader("Authorization", "Bearer " + token);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Request request = builder.build();
 | 
			
		||||
        return client.newCall(request).execute();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Response sendGetHttpRequest(String url, Map<String, String> queryParams, String token) throws IOException {
 | 
			
		||||
        OkHttpClient client = new OkHttpClient();
 | 
			
		||||
 | 
			
		||||
        HttpUrl.Builder httpBuilder = HttpUrl.parse(url).newBuilder();
 | 
			
		||||
        //封装请求参数
 | 
			
		||||
        if (queryParams != null) {
 | 
			
		||||
            for (Map.Entry<String, String> param : queryParams.entrySet()) {
 | 
			
		||||
                httpBuilder.addQueryParameter(param.getKey(), param.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        //设置请求的url
 | 
			
		||||
        Request.Builder requestBuilder = new Request.Builder()
 | 
			
		||||
                .url(httpBuilder.build());
 | 
			
		||||
 | 
			
		||||
        if (token != null && !token.isEmpty()) {
 | 
			
		||||
            requestBuilder.addHeader("Authorization", "Bearer " + token);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Request request = requestBuilder.build();
 | 
			
		||||
        //发送请求并返回响应数据
 | 
			
		||||
        return client.newCall(request).execute();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue