package com.changhong.epc.zuul.service.impl;
|
|
import com.changhong.epc.constter.base.BaseConst;
|
import com.changhong.epc.constter.exception.EPCServiceException;
|
import com.changhong.epc.constter.system.UserInfo;
|
import com.changhong.epc.constter.system.UserInfo.LogInInfo;
|
import com.changhong.epc.constter.system.prop.ChangHongProperties;
|
import com.changhong.epc.constter.system.prop.ChangHongProperties.PassPortName;
|
import com.changhong.epc.rely.api.service.CscApiService;
|
import com.changhong.epc.rely.api.tool.CscAesUtils;
|
import com.changhong.epc.zuul.service.LoginService;
|
import com.changhong.epc.zuul.util.HttpUtil;
|
import com.iemsoft.framework.cloud.core.password.Des;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import com.iemsoft.framework.cloud.core.tools.Assert;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.ui.ModelMap;
|
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.concurrent.TimeoutException;
|
|
//import com.changhong.ubp.login.service.CscApiService;
|
|
@Service("loginService")
|
public class LoginServiceImpl implements LoginService, BaseConst {
|
|
@Resource
|
private CscApiService cscApiService;
|
|
@Value("${aes.key:0123456789ABCDEF}")
|
private String aesKey;
|
|
// @Autowired
|
// private RedisTemplate<String, Object> redisTemplate;
|
|
private static final Map<String, UserInfo> USER_INFOS = new HashMap<>();
|
|
private static String infoId=ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp";
|
|
/**
|
* 获得用户信息类
|
*/
|
@Autowired
|
private UserInfoServiceImpl userInfoService;
|
|
|
@Override
|
public UserInfo getUserInfo(LogInInfo loginInfo) {
|
if(Objects.equals(loginInfo.getOpenId(),"test")){
|
return JSONTool.toObj("{\"birthday\":\"2016-02-02\",\"bpsUserName\":\"76_13_17_1_ubp\",\"changeTimes\":\"1\",\"city\":\"石家庄市\",\"county\":\"市辖区\",\"emailVerified\":\"0\",\"interests\":\"\",\"ipAddress\":\"54.222.240.185\",\"isSuperManager\":true,\"loginInfo\":{\"openId\":\"893ccd52f0ec4eae\",\"token\":\"0e704547f54583ad430fe09f83e4b524\"},\"loginTime\":\"2017-11-23 13:23:26\",\"passwordStrength\":\"1\",\"phone\":\"15140615455\",\"pkgName\":\"http://chweb.changhong.com\",\"province\":\"河北省\",\"registerTime\":\"2017-05-16 14:28:14\",\"sex\":\"男\",\"uid\":\"\",\"updateTime\":\"2017-10-24 19:51:20\",\"userCode\":\"893ccd52f0ec4eae\",\"userName\":\"王煜鑫\",\"workFlowCode\":\"D1B67990431B7788CF09CECBC3B938B6\"}", UserInfo.class);
|
}
|
ThreadData.set(OPEN_ID, loginInfo.getOpenId());
|
// String token=redisTemplate.opsForValue().get(loginInfo.getOpenId()).toString();
|
// if(!Objects.equals(token, loginInfo.getToken())){
|
// //Assert.empty(null, N0001);
|
// throw new EPCServiceException(N0001, N0001);
|
// }
|
|
return userInfoService.getUserInfo(loginInfo);
|
}
|
|
@Override
|
public UserInfo getUserInfo(String token) {
|
return getUserInfo(getLoginInfo(token));
|
}
|
|
@Override
|
public UserInfo getUserInfo(LoginSecurity loginSecurity) {
|
if(Objects.equals(loginSecurity.getOpenId(),"test")){
|
return JSONTool.toObj("{\"birthday\":\"2016-02-02\",\"bpsUserName\":\"76_13_17_1_ubp\",\"changeTimes\":\"1\",\"city\":\"石家庄市\",\"county\":\"市辖区\",\"emailVerified\":\"0\",\"interests\":\"\",\"ipAddress\":\"54.222.240.185\",\"isSuperManager\":true,\"loginInfo\":{\"openId\":\"893ccd52f0ec4eae\",\"token\":\"0e704547f54583ad430fe09f83e4b524\"},\"loginTime\":\"2017-11-23 13:23:26\",\"passwordStrength\":\"1\",\"phone\":\"15140615455\",\"pkgName\":\"http://chweb.changhong.com\",\"province\":\"河北省\",\"registerTime\":\"2017-05-16 14:28:14\",\"sex\":\"男\",\"uid\":\"\",\"updateTime\":\"2017-10-24 19:51:20\",\"userCode\":\"893ccd52f0ec4eae\",\"userName\":\"王煜鑫\",\"workFlowCode\":\"D1B67990431B7788CF09CECBC3B938B6\"}", UserInfo.class);
|
}
|
return getUserInfo(new LogInInfo(loginSecurity.getToken(), loginSecurity.getOpenId()));
|
}
|
|
@Override
|
public LogInInfo getLoginInfo(String token) {
|
LogInInfo loginInfo = JSONTool.toObj(
|
new Des().strEnc(token, UserInfo.FIRST_KEY, UserInfo.SECOND_KEY, UserInfo.THIRD_KEY), LogInInfo.class);
|
Assert.empty(loginInfo, U0002);
|
return loginInfo;
|
}
|
|
@Service
|
public class UserInfoServiceImpl{
|
|
@Autowired
|
private ChangHongProperties changHongProperties;
|
|
/**
|
* 获得userInfo
|
* @param loginInfo
|
* @return
|
*/
|
// @CacheSave(time=1 * 60 * 60 * 24)
|
public UserInfo getUserInfo(LogInInfo loginInfo){
|
// System.out.println(">>>>>"+loginInfo);
|
UserInfo userInfo = null;
|
try {
|
userInfo = HttpUtil.get(
|
changHongProperties.getPassUrl(PassPortName.USER_DETIAL
|
, new ModelMap("token", loginInfo.getToken())
|
.addAttribute("openId", loginInfo.getOpenId())
|
.addAttribute("livemode", changHongProperties.getSsoLivemode()))
|
, null, UserInfo.class);
|
} catch (TimeoutException e) {
|
throw new EPCServiceException(N0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.USER_DETIAL, null));
|
}
|
Assert.empty(userInfo, N0001);
|
userInfo.setLoginInfo(loginInfo);
|
userInfo.setAesOpenId(CscAesUtils.encrypt(userInfo.getLoginInfo().getOpenId(), aesKey));
|
//setEmpInfo(userInfo);
|
return userInfo;
|
}
|
/*
|
18273479217:12345678
|
15140615455:12345678
|
15882806952:hr753753
|
18681661636:12345678
|
17615151309:12345678
|
*/
|
// private void setEmpInfo(UserInfo userInfo) {
|
// String userId="";
|
// if(ObjectUtil.notEmpty(userInfo.getPhone())&&ObjectUtil.notEmpty(ThreadData.get(TENANT_ID))){
|
// userId=getUserId(userInfo.getPhone() );
|
// userInfo.setUid(userId);
|
// }
|
// //ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp")
|
// if(ObjectUtil.notEmpty(userId)){
|
// userInfo.setBpsUserName((userId+"_"+ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp"));
|
// userInfo.setWorkFlowCode(new Des().strEnc((userId+"_"+ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp").toString(), UserInfo.FIRST_KEY, UserInfo.SECOND_KEY, UserInfo.THIRD_KEY));
|
// }else{
|
// userInfo.setBpsUserName("sysadmin");
|
// userInfo.setWorkFlowCode(new Des().strEnc(("sysadmin").toString(), UserInfo.FIRST_KEY, UserInfo.SECOND_KEY, UserInfo.THIRD_KEY));
|
// }
|
// userInfo.setUserCode(userInfo.getLoginInfo().getOpenId());
|
// if(ThreadData.get(Keys.TENANT_ID) != null){
|
// userInfo.setTenantId(ThreadData.get(TENANT_ID));
|
// }
|
// }
|
// }
|
// public String getUserId(String phone){
|
// String userId="";
|
// if(!(ThreadData.get(Keys.APP_KEY).toString().contains(phoneAppKey))){
|
// // Object users=redisTemplate.opsForValue().get(ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp"+"allParticipantUser");
|
// List<WFParticipantEntity> allUser=new ArrayList<>();
|
//// if(ObjectUtil.notEmpty(users)){
|
//// allUser=JSONTool.toList(users.toString(), WFParticipantEntity.class);
|
//// }else{
|
// com.changhong.epc.constter.system.Service se=new com.changhong.epc.constter.system.Service();
|
// se.setAppId(ThreadData.get(COMPANY_ID));
|
// se.setAccessId(ThreadData.get(ACCESS_ID));
|
// se.setSecurityKey(ThreadData.get(SECURITY_KEY));
|
// List<WFParticipantEntity> pList=cscApiService.findOrganizationByCompanyId(se);
|
// getAllUsers(pList,allUser);
|
// // }
|
// // allUser=JSONTool.toList(redisTemplate.opsForValue().get(ThreadData.get(TENANT_ID)+"_"+ThreadData.get(COMPANY_ID)+"_"+ThreadData.get(SERVICE_ID)+"_"+"ubp"+"allParticipantUser").toString(),WFParticipantEntity.class);
|
// for( WFParticipantEntity user:allUser){
|
// if(Objects.equals(phone,user.getPhone())){
|
// userId=user.getId();
|
// }
|
// }
|
// }
|
// return userId;
|
// }
|
|
|
// public static void getAllUsers(List<WFParticipantEntity> pList,List<WFParticipantEntity> orgData){
|
// for(WFParticipantEntity org:pList){
|
// if("emp".equals(org.getTypeCode())){
|
// orgData.add(org);
|
// }
|
// if(ObjectUtil.notEmpty(org.getChildren()) ){
|
// getAllUsers(org.getChildren(),orgData);
|
// }
|
// }
|
}
|
|
}
|