|
|
@ -10,9 +10,7 @@ import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.PhoneValidatorUtils; |
|
|
|
import com.epmet.dto.CustomerStaffDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.LatestStaffWechatLoginResultDTO; |
|
|
|
import com.epmet.dto.result.StaffGridInfoResultDTO; |
|
|
|
import com.epmet.dto.result.UserTokenResultDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
|
import com.epmet.feign.GovOrgFeignClient; |
|
|
|
import com.epmet.feign.MessageFeignClient; |
|
|
@ -26,6 +24,7 @@ import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -96,7 +95,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
* @Date 2020/4/18 21:11 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public Result getorgs(GovWxmpGetOrgsFormDTO formDTO) { |
|
|
|
public Result<List<StaffOrgsResultDTO>> getMyOrg(StaffOrgsFormDTO formDTO) { |
|
|
|
//1、根据手机号查询到用户信息
|
|
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
|
|
|
if (!customerStaffResult.success()) { |
|
|
@ -104,12 +103,19 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
return new Result().error(customerStaffResult.getCode()); |
|
|
|
} |
|
|
|
//2、验证码是否正确
|
|
|
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO); |
|
|
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO.getMobile()); |
|
|
|
if (!formDTO.getSmsCode().equals(rightSmsCode)) { |
|
|
|
return new Result<>().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
|
return new Result<List<StaffOrgsResultDTO>>().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
|
} |
|
|
|
//3、TODO返回组织树
|
|
|
|
return new Result(); |
|
|
|
//3、查询用户所有的组织信息
|
|
|
|
List<String> customerIdList = new ArrayList<>(); |
|
|
|
for (CustomerStaffDTO customerStaffDTO : customerStaffResult.getData()) { |
|
|
|
customerIdList.add(customerStaffDTO.getCustomerId()); |
|
|
|
} |
|
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -129,12 +135,34 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
//4、获取用户token
|
|
|
|
String token = this.generateGovWxmpToken(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
//5、保存到redis
|
|
|
|
this.saveGovTokenDto(latestStaffWechatLoginDTO.getOrgId(), latestStaffWechatLoginDTO.getGridId(), latestStaffWechatLoginDTO.getStaffId(), wxMaJscode2SessionResult, token); |
|
|
|
this.saveLatestGovTokenDto(latestStaffWechatLoginDTO, wxMaJscode2SessionResult, token); |
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
|
} |
|
|
|
|
|
|
|
//保存tokenDto到redis
|
|
|
|
private void saveLatestGovTokenDto(LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
|
|
|
String token) { |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
GovTokenDto govTokenDto = new GovTokenDto(); |
|
|
|
govTokenDto.setApp(LoginConstant.APP_GOV); |
|
|
|
govTokenDto.setClient(LoginConstant.CLIENT_WXMP); |
|
|
|
govTokenDto.setStaffId(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
govTokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); |
|
|
|
govTokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); |
|
|
|
govTokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid()); |
|
|
|
govTokenDto.setToken(token); |
|
|
|
govTokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
govTokenDto.setOrgId(latestStaffWechatLoginDTO.getOrgId()); |
|
|
|
govTokenDto.setGridId(latestStaffWechatLoginDTO.getGridId()); |
|
|
|
govTokenDto.setCustomerId(latestStaffWechatLoginDTO.getCustomerId()); |
|
|
|
cpUserDetailRedis.set(govTokenDto, expire); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
} |
|
|
|
|
|
|
|
//保存登录日志
|
|
|
|
private Result saveStaffLoginRecord(LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO) { |
|
|
|
StaffLoginHistoryFormDTO staffLoginHistoryFormDTO = new StaffLoginHistoryFormDTO(); |
|
|
@ -164,19 +192,30 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(LoginConstant.APP_GOV, formDTO.getWxCode()); |
|
|
|
//3、记录staff_wechat
|
|
|
|
this.savestaffwechat(customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid()); |
|
|
|
//4、记录登录日志
|
|
|
|
StaffGridInfoFormDTO staffGridInfoFormDTO = new StaffGridInfoFormDTO(); |
|
|
|
//4、查询用户绑定的网格
|
|
|
|
StaffLatestLoginGridResultDTO latestGridInfo = this.getLatestGridInfo(formDTO, customerStaff.getUserId()); |
|
|
|
//5、记录登录日志
|
|
|
|
this.saveStaffLoginRecord(formDTO, customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid(), latestGridInfo.getGridId()); |
|
|
|
//1、获取用户token
|
|
|
|
String token = this.generateGovWxmpToken(customerStaff.getUserId()); |
|
|
|
//2、保存到redis
|
|
|
|
this.saveGovTokenDto(formDTO.getOrgId(), formDTO.getCustomerId(), latestGridInfo.getGridId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); |
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
|
} |
|
|
|
|
|
|
|
//查询用户绑定的网格
|
|
|
|
private StaffLatestLoginGridResultDTO getLatestGridInfo(GovWxmpEnteOrgFormDTO formDTO, String userId) { |
|
|
|
StaffLatestLoginGridFormDTO staffGridInfoFormDTO = new StaffLatestLoginGridFormDTO(); |
|
|
|
staffGridInfoFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
|
|
staffGridInfoFormDTO.setOrgId(formDTO.getOrgId()); |
|
|
|
staffGridInfoFormDTO.setStaffId(customerStaff.getUserId()); |
|
|
|
Result<List<StaffGridInfoResultDTO>> staffGridInfoListResult = govOrgFeignClient.getStaffGridInfo(staffGridInfoFormDTO); |
|
|
|
String gridId = null; |
|
|
|
if (staffGridInfoListResult.success() && null != staffGridInfoListResult.getData() && staffGridInfoListResult.getData().size() > 0) { |
|
|
|
gridId = staffGridInfoListResult.getData().get(0).getGridId(); |
|
|
|
staffGridInfoFormDTO.setStaffId(userId); |
|
|
|
Result<StaffLatestLoginGridResultDTO> staffGridInfoListResult = govOrgFeignClient.getStaffLatestLoginGrid(staffGridInfoFormDTO); |
|
|
|
if (staffGridInfoListResult.success() && null != staffGridInfoListResult.getData()) { |
|
|
|
return staffGridInfoListResult.getData(); |
|
|
|
} |
|
|
|
this.saveStaffLoginRecord(formDTO, customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid(), gridId); |
|
|
|
UserTokenResultDTO userTokenResultDTO = this.getAuthorizationInfo(formDTO.getOrgId(), gridId, customerStaff.getUserId(), wxMaJscode2SessionResult); |
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
|
return new StaffLatestLoginGridResultDTO(); |
|
|
|
} |
|
|
|
|
|
|
|
//保存登录日志
|
|
|
@ -192,18 +231,6 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
return staffLoginRecordResult; |
|
|
|
} |
|
|
|
|
|
|
|
private UserTokenResultDTO getAuthorizationInfo(String orgId, |
|
|
|
String gridId, |
|
|
|
String staffId, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult) { |
|
|
|
//1、获取用户token
|
|
|
|
String token = this.generateGovWxmpToken(staffId); |
|
|
|
//2、保存到redis
|
|
|
|
this.saveGovTokenDto(orgId, gridId, staffId, wxMaJscode2SessionResult, token); |
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return userTokenResultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param userId |
|
|
@ -217,7 +244,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
StaffWechatFormDTO staffWechatFormDTO = new StaffWechatFormDTO(); |
|
|
|
staffWechatFormDTO.setUserId(userId); |
|
|
|
staffWechatFormDTO.setWxOpenId(openid); |
|
|
|
return epmetUserFeignClient.savestaffwechat(staffWechatFormDTO); |
|
|
|
return epmetUserFeignClient.saveStaffWechat(staffWechatFormDTO); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -238,11 +265,12 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
* @Description 生成token |
|
|
|
* @Date 2020/4/18 23:04 |
|
|
|
**/ |
|
|
|
private String saveGovTokenDto(String orgId, |
|
|
|
String gridId, |
|
|
|
String staffId, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
|
|
|
String token) { |
|
|
|
private void saveGovTokenDto(String orgId, |
|
|
|
String customerId, |
|
|
|
String gridId, |
|
|
|
String staffId, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
|
|
|
String token) { |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
GovTokenDto govTokenDto = new GovTokenDto(); |
|
|
|
govTokenDto.setApp(LoginConstant.APP_GOV); |
|
|
@ -256,9 +284,9 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
govTokenDto.setOrgId(orgId); |
|
|
|
govTokenDto.setGridId(gridId); |
|
|
|
govTokenDto.setCustomerId(customerId); |
|
|
|
cpUserDetailRedis.set(govTokenDto, expire); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
return token; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|